Sign in to follow this  
Followers 0
taurus905

SQLite Examples

3 posts in this topic

I am trying to find real examples of SQLite that actually produce an output so I can then read the code to see what it did.

To me, a bad example of a script is one that runs and then ends without producing any output. I guess there are some uses for these scripts, but it is hard for me to see without taking too much time to try to figure out what the point was.

If someone can point out to me the intended purpose of the following script in the help file is, I would appreciate it. I do realize that some examples are put together quickly and having a bad example is better than nothing at all. So don't get me wrong. I thank the people who have taken their valuable time to write the help file in order to give the rest of us some direction.

Most of all, I would like this thread to be a place to post scripts or links to scripts that are good examples of SQLite.

Thank you to all who reply in a positive manner.

taurus905

#include <SQLite.au3>
Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup ()
If @error > 0 Then
    MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit - 1
EndIf
_SQLite_Open (); Open a :memory: database
If @error > 0 Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit - 1
EndIf

;Example Table
;   Name        | Age
;   -----------------------
;   Alice      | 43
;   Bob      | 28
;   Cindy      | 21

If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())

; Query
$iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then
    _SQLite_Display2DResult($aResult)

;~  $aResult looks like this:
;~  
;~   Name   Age 
;~   Alice  43  
;~   Bob    28  
;~   Cindy  21  
;~
;~  If the dimensions would be switched in _SQLite_GetTable2d the result would look like this:
;~  
;~   Name  Alice  Bob  Cindy 
;~   Age   43    28   21    

Else
    MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
EndIf

_SQLite_Close ()
_SQLite_Shutdown ()

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Share this post


Link to post
Share on other sites



Hi,

Shows output of "_SQLite_GetTable2d" on console...

you can adjust to use arraydisplay easily enough, but they were all written before current version with GUI.

Best, randall

randallc,

Thank you for reminding me about the output to the console. I knew that and had used it before. I was just tired when I tried it again and wrote this post. I should have just read the script.

But if anyone has any other examples of SQLite, please post them here.

taurus905


"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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