Sign in to follow this  
Followers 0
bogQ

SQLite how to return column with all rows?

6 posts in this topic

#1 ·  Posted (edited)

i know i can return single cell and drive my way around until i reach end of columns, but i'm concerned about the speed because i have large amounts of columns.

so basicly i need

_SQlite_Query (-1, "SELECT c FROM aTest ORDER BY a;", $hQuery) that will work on columns (column identified by the row cell data) and not on rows and to return entire row

So for now i have

Func _SQLite_GetTable2dRange($sTable,$iStart,$iRange)
    Local $aResult, $iRows, $iColumns
    Local $return = _SQLite_GetTable2d (-1,"SELECT ROWID,* FROM "&$sTable&" LIMIT "&$iRange&" OFFSET "&$iStart-1&";",$aResult,$iRows,$iColumns)
    _ArrayDisplay($aResult, "Query Result")
    Return $aResult
EndFunc

but i dont know how to get location of the row to use as $iStart

Any suggestions to what should i use for it or some other suggestion?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What is your schema and which column(s) are you interested with, on which condition(s) and for which range?

Answer all that and your SELECT is built.

How much is "large" ?

Show your schema, the queries you need and I'll guide you.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

large is (i planed around) 250 columns (but at the moment i have them around 90 on 4 places and im looking to join them on one place) with max around 10k lines, column is unique 'EducatorID' number in range from from 100001 to 999999, other columns are additional data that can be duplicated

but never the less i think i got it

Func _SQLite_GetLine2dByData($sTable,$sColumn,$sData)
    Local $aResult, $iRows, $iColumns
    Local $return = _SQLite_GetTable2d (-1,"SELECT ROWID,* FROM "&$sTable&" WHERE "&$sColumn&" ='"&$sData&"';",$aResult,$iRows,$iColumns)
    _ArrayDisplay($aResult, "Query Result")
    Return $aResult
EndFunc
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

large is (i planed around) 250 columns (but at the moment i have them around 90 on 4 places and im looking to join them on one place)

Impressive. Are you sure your schema in decently normalized? 250 colums souds more than plenty!

with max around 10k lines, column is unique 'EducatorID' number in range from from 100001 to 999999

Then make it your rowid alias as EducatorID INTEGER PRIMARY KEY NOT NULL

I insist on INTEGER here, INT wouldn't work as well.

other columns are additional data that can be duplicated

Care to explain that duplication? I suspect you're having data (columns) that should make it in a separate table(s).

Let me explain: you should never have a schema like this:

ID INTEGER primary key ...,

Name char,

Birthday char

Address1 xxx

Address2 xxx

Address3 xxx

...

AddressN xxx

Mail1 char

Mail2 char

...

MailN char

Here Addresses at one hand and mails at the other will need to reside in two new separate tables, linked by foreign key on ID.

Func _SQLite_GetLine2dByData($sTable,$sColumn,$sData)
    Local $aResult, $iRows, $iColumns
    Local $return = _SQLite_GetTable2d (-1,"SELECT ROWID,* FROM "&$sTable&" WHERE "&$sColumn&" ='"&$sData&"';",$aResult,$iRows,$iColumns)
    _ArrayDisplay($aResult, "Query Result")
    Return $aResult
EndFunc
Not efficient. Make $Result a ByRef variable handled by the caller.

Now if you're only interested by a certain column, why the * ?

Then, using * is a bad idea in many cases. Should your schema change by, say, adding a new column or reorganizing the column order for better efficiency, your program would need changed accordingly.

But if you go pas the initial pain and type the column names in the order you whish, you don't have this issue.

Quote your string data to protect from embedded single quotes: if $Data = "O'Connor" your SQL will err out. Use _SQLite_Escape() or (much better) _SQLite_FastEscape() from the last beta.

Same thing for your columns: if you have the (questionable) idea to name a column Table or have it called MY LARGE TABLE with embedded spaces, then the statement won't work. Use double quotes around schema names "My Large Table" or square brackets [My Large Table].

Edit: please make it SQLite in the title (for easier search match)

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Impressive. Are you sure your schema in decently normalized? 250 colums souds more than plenty!

240 dayes +-1 day + cells 16 with personal info = around 250 maby +10, in every cell (where $string&$date is column name) is around 30~60 ChildID-s

Care to explain that duplication?

duplication like first name as single cell or town as single cell

I suspect you're having data (columns) that should make it in a separate table(s).

sounds about correct but i dont see why the point in putting them into 2 separate tables +16 rows dont make alot of diffrance on 250 rows

;Example Table
;   EducatorID|FirstName|LastName  |... Date2011*|Date2011*    |Date2011*    |...
;   -----------------------
;   100001    |Darko    |Djurdjevic|100001;100002|100001;100003|400001;100005|
;   100002    |Milan    |Mancic    |100003;100004|100002;100004|100001;100003|
;   100003    |Skomi    |Miloscic  |100005;100006|100005;100006|100002;100006|

Now if you're only interested by a certain column, why the * ?

because i don't have better idea, i'm open for suggestions of how to input my row request, after all that is why im heare :D Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

OK. This is turning into yet another SQL rallye (I was about sure it was).

Let's put that in PMs right now since it's completely out of AutoIt topics. I don't want to get moderated/banned for loving SQLite too much!

At the end, feel free to post a final result here so that other readers don't get frustrated.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0