Jump to content
AndyS01

_SQLite_Open exits immediately

Recommended Posts

When I try to open a SQLite database, the script exits within the _SQLite_Open() function.
I have debugged the code in SQLite3.au3 and the culprit is the DLL call to xx.  Specifically to this code:

Local $avRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_open_v2", "struct*", $tFilename, _ ; UTF-8 Database filename
            "ptr*", 0, _ ; OUT: SQLite db handle
            "int", $iAccessMode, _ ; database access mode
            "ptr", 0)

Using ConsoleWrite() calls, I have determined that the script makes it to the DLLCall, but exits without returning from it.  I have examined the DLL file and I see the sqlite3_open_v2 entry.

Here is my test code:

#include <SQLite.au3>

_Main()

Func _Main()
    _SQLite_Startup("winSQLite3.dll")
    If @error Then
        MsgBox(0, "SQLite Error", "SQLite3.dll Can't be Loaded!")
        Exit -1
    EndIf

    ConsoleWrite("-  _SQLite_LibVersion = " & _SQLite_LibVersion() & @CRLF)

    _SQLite_Open() ; Creates a :memory: database and don't use its handle to refer to it

    ConsoleWrite("-" & @ScriptLineNumber & ": HERE" & @CRLF)

    If @error Then
        MsgBox(0, "SQLite Error", "Can't create a memory Database!")
        Exit -1
    EndIf

    _SQLite_Close()
    ConsoleWrite("-" & @ScriptLineNumber & ": HERE" & @CRLF)

    _SQLite_Shutdown()
EndFunc   ;==>_Main

 

Share this post


Link to post
Share on other sites
Posted (edited)

If your script is executing using the 64-bit AutoIt3 stub/interpreter, then the most likely issue is that the UDF will look for your dll name with "_x64" appended to the end of the file name.  So in your case, it will look for "winSQLite3_x64.dll". 

 

Also, using the syntax below will tell it to use the specified DLL path instead of searching for it:

_SQLite_Startup($sDllPath, Default, 1)

Where $sDllPath is the path to the DLL

 

Edited by TheXman

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites
2 hours ago, TheXman said:

If your script is executing using the 64-bit AutoIt3 stub/interpreter, then the most likely issue is that the UDF will look for your dll name with "_x64" appended to the end of the file name.  So in your case, it will look for "winSQLite3_x64.dll". 

 

Also, using the syntax below will tell it to use the specified DLL path instead of searching for it:

_SQLite_Startup($sDllPath, Default, 1)

Where $sDllPath is the path to the DLL

 

How do I know if I'm using the 64 bit stub/interpreter?

Share this post


Link to post
Share on other sites
16 minutes ago, Nine said:

Your ConsoleWrite after _SQLite_Open() erases @error.  So you are not testing the right result.

This is just test code to show that the ConsoleWrite never gets called.  The script exits first.

Share this post


Link to post
Share on other sites
Posted (edited)
15 minutes ago, AndyS01 said:

How do I know if I'm using the 64 bit stub/interpreter?

If you're running your script in the scite editor, look in the console and see whether if it was executed using "autoit3_x64.exe" or "autoit3.exe"  It will be a line similar to:

>Running:(3.3.14.5):C:\Portable Apps\AutoIt3\autoit3_x64.exe "C:\Projects\Personal\AutoIt\Test\a3_temp.au3"

 

Edited by TheXman

Share this post


Link to post
Share on other sites
4 minutes ago, TheXman said:

If you're running your script in the scite editor, look in the console and see whether if it was executed using "autoit3_x64.exe" or "autoit3.exe"  It will be a line similar to:

>Running:(3.3.14.5):C:\Portable Apps\AutoIt3\autoit3_x64.exe "C:\Projects\Personal\AutoIt\Test\a3_temp.au3"

 

Yup, I'm running the non 64 bit version:

Quote

Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe

 

Share this post


Link to post
Share on other sites
Posted (edited)

So you probably just need to change the _SQLite_Startup() line as I suggested above.

Example:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <SQLite.au3>

sqlite_forcelocal_example()

Func sqlite_forcelocal_example()
    Local $asData[0]

    Local $hQuery = 0

    Local $sMsg       = "", _
          $sVer       = "", _
          $sSqliteDll = ""


    ;Start up sqlite environment
    $sSqliteDll = _SQLite_Startup("c:\program files\sqlite\sqlite3.dll", Default, 1)
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_SQLite_Startup failed - @error = " & @error)

    ;Open a memory db
    _SQLite_Open()
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_SQLite_Open failed - @error = " & @error)

    ;Query for sqlite version
    If _SQLite_QuerySingleRow(-1, "Select sqlite_version();", $asData) = $sqlite_ok Then $sVer = $asData[0]

    ;Query for sqlite compile options
    If _SQLite_Query(-1, "pragma compile_options;", $hQuery) = $sqlite_ok Then
        ;Build output message
        $sMsg =  "DLL = " & $sSqliteDll & @CRLF
        $sMsg &= "VER = " & $sVer       & @CRLF & @CRLF

        While _SQLite_FetchData($hQuery, $asData) = $sqlite_ok
            $sMsg &= $asData[0] & @CRLF
        WEnd
    EndIf

    ;Display message
    ConsoleWrite("SQLite Compile Options" & @CRLF)
    ConsoleWrite($sMsg & @CRLF)

    ;Close db & shut down sqlite
    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc

Console output:

SQLite Compile Options
DLL = c:\program files\sqlite\sqlite3_x64.dll
VER = 3.35.5

COMPILER=msvc-1500
ENABLE_BYTECODE_VTAB
ENABLE_COLUMN_METADATA
ENABLE_DBSTAT_VTAB
ENABLE_FTS3
ENABLE_FTS4
ENABLE_FTS5
ENABLE_GEOPOLY
ENABLE_JSON1
ENABLE_MATH_FUNCTIONS
ENABLE_PREUPDATE_HOOK
ENABLE_RTREE
ENABLE_SESSION
ENABLE_STMTVTAB
MAX_TRIGGER_DEPTH=100
TEMP_STORE=1
THREADSAFE=1

 

Edited by TheXman

Share this post


Link to post
Share on other sites

I added a couple of ConsoleWrites to see the progress.  There were many sqlite3.dll and winsqlite3.dll files on my hard drive.  When I pointed to a sqlite3.dll in the AutoIT data directory, I got an "_SQLite_Startup failed - @error = 1" error.  When I pointed to a winsqlite3.dll file, the test script never returns from the _SQLite_Open() (by debugging, I see that the _SQLite_Open() code never returns from the sqlite3_open_v2  dll call).  When I examined the DLL entry points for each file, I see the sqlite3_open_v2 entry point.

#include <Constants.au3>
#include <SQLite.au3>

sqlite_forcelocal_example()

Func sqlite_forcelocal_example()
    Local $asData[0]

    Local $hQuery = 0

    Local $sMsg       = "", _
          $sVer       = "", _
          $sSqliteDll = ""

ConsoleWrite("+++:" & @ScriptLineNumber & ": HERE" & @crlf)
    ;Start up sqlite environment
    local $dllfn

;~  $dllfn = "C:\Windows\SysWOW64\winsqlite3.dll"
    $dllfn = "C:\Users\Andy\AppData\Local\AutoIt v3\SQLite\sqlite3_x64_302700200.dll"
    $sSqliteDll = _SQLite_Startup($dllfn, Default, 1)
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_SQLite_Startup failed - @error = " & @error)

ConsoleWrite("+++:" & @ScriptLineNumber & ": HERE" & @crlf)
    ;Open a memory db
    _SQLite_Open()
    If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_SQLite_Open failed - @error = " & @error)
ConsoleWrite("+++:" & @ScriptLineNumber & ": HERE" & @crlf)

    ;Query for sqlite version
    If _SQLite_QuerySingleRow(-1, "Select sqlite_version();", $asData) = $sqlite_ok Then $sVer = $asData[0]

    ;Query for sqlite compile options
    If _SQLite_Query(-1, "pragma compile_options;", $hQuery) = $sqlite_ok Then
        ;Build output message
        $sMsg =  "DLL = " & $sSqliteDll & @CRLF
        $sMsg &= "VER = " & $sVer       & @CRLF & @CRLF

        While _SQLite_FetchData($hQuery, $asData) = $sqlite_ok
            $sMsg &= $asData[0] & @CRLF
        WEnd
    EndIf

    ;Display message
    ConsoleWrite("SQLite Compile Options" & @CRLF)
    ConsoleWrite($sMsg & @CRLF)

    ;Close db & shut down sqlite
    _SQLite_Close()
    _SQLite_Shutdown()
EndFunc

 

Share this post


Link to post
Share on other sites

I just tried "C:\Users\Andy\AppData\Local\AutoIt v3\SQLite\sqlite3_302700200.dll" and your example produced the following:

+++:15: HERE
+++:25: HERE
+++:29: HERE
SQLite Compile Options
DLL = C:\Users\Andy\AppData\Local\AutoIt v3\SQLite\sqlite3_302700200.dll
VER = 3.27.2

COMPILER=msvc-1916
ENABLE_COLUMN_METADATA
ENABLE_FTS3_PARENTHESIS
ENABLE_FTS4
ENABLE_RTREE
THREADSAFE=1

So I guess that I need to find a 'real' sqlite3.dll file. Can you suggest a good place to find one?

Share this post


Link to post
Share on other sites
3 hours ago, AndyS01 said:

So I guess that I need to find a 'real' sqlite3.dll file.

What’s not “real” about yours? 


Code hard, but don’t hard code...

Share this post


Link to post
Share on other sites

@AndyS01 your test succeded, but your dll is quite old. You can always grab the latest stable release for Windows (x86 or x64, your choice) from the official download site: https://www.sqlite.org/download.html

Lookup "Precompiled Binaries for Windows"


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
6 minutes ago, JockoDundee said:

What’s not “real” about yours? 

Well, on my hard drive, there are 23 dll files  whose names match '*sqlite*.dll",  Of those, there are 14 unique file sizes.  As I intend to embed the dll file into my compiled .au3 script, I need to make sure that I have one that is the most recent from an official web site.  I will test each of the files on my hard drive, but I'm not sure about using files like "C:\Users\Andy\AppData\sqlite3_x64_302700200.dll".

Share this post


Link to post
Share on other sites

Whatever name you give to the x64 DLL, don't forget to append _64 at the end of the filename. This allows to use the same code compiled for 32- or 64-bit.

$sSqliteDll = _SQLite_Startup("mypath\sqlite3.dll", Default, 1)

will use mypath\sqlite3.dll when compiled for x86 and mypath\sqlite3_x64.dll when compiled for x64.


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
1 hour ago, AndyS01 said:

I need to make sure that I have one that is the most recent from an official web site.  I will test each of the files on my hard drive, but I'm not sure about using files like "C:\Users\Andy\AppData\sqlite3_x64_302700200.dll".

Ok, but then why are you testing 23 dills on your hard drive instead of just downloading the “real” one?


Code hard, but don’t hard code...

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi everyone! i have Two-Problems:
      I've used this code to decode and export cookies from Google Chrome application's "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Cookie" file but i can't receive any data: #include <CryptProtect.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Global Const $g_sLoc_Output = @ScriptDir & "\Cookies.txt" If FileExists($g_sLoc_Output) Then FileDelete($g_sLoc_Output) EndIf $hFO_Output = FileOpen($g_sLoc_Output ,1) If $hFO_Output <> -1 Then FileWrite($hFO_Output, Chrome()) FileFlush($hFO_Output) FileClose($hFO_Output) EndIf Func Chrome() Local $q, $r, $sOutput, $sLoc_ChromeDB = EnvGet("localappdata") & "\Google\Chrome\User Data\Default\Cookies" If FileExists($sLoc_ChromeDB) = False Then Return "" _SQLite_Startup() If @error Then MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded! - " & $__g_hPrintCallback_SQLite & @CRLF & @CRLF & "Exiting application") Exit -1 EndIf _SQLite_Open($sLoc_ChromeDB) _SQLite_Query(-1, 'SELECT host_key, name, value, encrypted_value FROM cookies', $q) While _SQLite_FetchData($q, $r) = 0 $sOutput = $sOutput & r[0] & @CRLF & r[1] WEnd _SQLite_Close() _SQLite_Shutdown() Return $sOutput EndFunc I've used this code too for decrypt my saved passwords and export from Google Chrome application's "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Login Data" file but i can't get decrypted data: #include <CryptProtect.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Global Const $g_sLoc_Output = @ScriptDir & "\Credentials.txt" If FileExists($g_sLoc_Output) Then FileDelete($g_sLoc_Output) EndIf $hFO_Output = FileOpen($g_sLoc_Output ,1) If $hFO_Output <> -1 Then FileWrite($hFO_Output, Chrome()) FileFlush($hFO_Output) FileClose($hFO_Output) EndIf Func Chrome() Local $q, $r, $sOutput, $sLoc_ChromeDB = EnvGet("localappdata") & "\Google\Chrome\User Data\Default\Login Data" If FileExists($sLoc_ChromeDB) = False Then Return "" _SQLite_Startup() If @error Then MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded! - " & $__g_hPrintCallback_SQLite & @CRLF & @CRLF & "Exiting application / Zavolej Honzovi") Exit -1 EndIf _SQLite_Open($sLoc_ChromeDB) _SQLite_Query(-1, "select * from logins;", $q) While _SQLite_FetchData($q, $r) = 0 $sOutput = $sOutput & "======================| " & $r[7] & " |======================" & @CRLF & "Login URL: " & $r[0] & @CRLF & "Email/User: " & $r[3] & @CRLF & "Password: " & _CryptUnprotectData($r[5], "") & @CRLF & @CRLF WEnd _SQLite_Close() _SQLite_Shutdown() Return $sOutput EndFunc Thanks!
    • By Skeletor
      Hi All,
      Here's a really simple question. 
      I ran the code from the helpfile under: _SQLite_Open

      Issue is I end up with an error message: SQLite3.dll Can't be Loaded!
      I placed the *.dll in the include folder, but still nothing. 

      Where must this file be placed.
       
    • By Skysnake
      ; works Local $sqlCLI = 'sqlite3.exe C:/Users/AppData/Local/Temp/~knakvog.tmp ".read sql2csv.txt" ' Local $sqlCLI = 'sqlite3.exe C:/Users/AppData/Local/Temp/~knakvog.tmp < xpt2csv.txt ' Local $openCSV = Run(@ComSpec & " /k " & $sqlCLI,@ScriptDir,@SW_HIDE) Much less impressive than I hoped for.
      Change the @SW_HIDE to MAX to see the results of the labour. 
      It appears as if SQLITE3.EXE can accept one argument after the dbfile name, so the ".read..." works.  But it does not allow multiple consecutive parameters.
      -- sql text file content sql2.csv.txt .headers on .mode csv .once dataout.csv SELECT * FROM memCSV; .system dataout.csv .quit The above line reads the 'sql2csv.txt' file using either of the "< or .read" options, and executes correctly.
      Trying to stipulate all in the AutoIt command line results in failure
      Line below does NOT work. 
      ; not working Local $sqlCLI = 'sqlite3.exe "C:/Users/AppData/Local/Temp/~knakvog.tmp" ".headers on" ".mode csv" ".once dataout.csv" SELECT * FROM memCSV; ".system dataout.csv" ' Failure appears to be a native SQLITE3 "too many parameters" issue and not related to AutoIt.  
    • By jvds
      when i try to run my code i get the folowing error
      @@ Debug(257) : __SQLite_Download_SQLite3File : $URL = http://www.autoitscript.com/autoit3/files/beta/autoit/archive/sqlite/sqlite3.dll
          $sTempfile = C:\DOCUME~1\user\CONFIG~1\Temp\~hdyarac.dll
      >Error: 13
      #include <SQLite.au3> #include <SQLite.dll.au3> Local $aResult, $iRows, $iColumns, $iRval Local $hFile, $vData, $sFileName, $sData, $hQuery, $aRow, $sMsg _SQLite_Startup() ConsoleWrite("_SQLite_Startup" & @LF) ;~ ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) Local $sqldb = _SQLite_Open('DB') only on a WinXP computer, it works on win7, any idea what it may be?
    • By Skysnake
      Hi
      Could not find the sqlite3_progress_handler in the AutoIt Forum.
      SQLITE link is here https://www.sqlite.org/c3ref/progress_handler.html (sorry, LINK insert not working)
      I wrote the code below based on examples from the SQLITE.AU3 include.  I do not understand the possible errors.  Also, I am not familiar with the the "C" syntax.
      Comments and improvements are greatly appreciated.
      Func _SQLite_Progress($hDB = -1, $iTimer = 1000,$sCallback = "_cb",$Param = 1) If __SQLite_hChk($hDB, 2) Then Return SetError(@error, 0, $SQLITE_MISUSE) If $iTimer = Default Then $iTimer = 1000 If $sCallback = Default Then $sCallback = "_cb" If $Param = Default Then $Param = 1 Local $avRval = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_progress_handler", _ "ptr", $hDB, _ ; D An open database connection "int", $iTimer, _ ; N the number of virtual machine instructions to evaluate between successive callbacks "int", $sCallback, _ ; X user defined callback function "ptr", $Param) ; P only parameter passed to callback X If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error If $avRval[0] <> $SQLITE_OK Then SetError(-1) Return $avRval[0] EndFunc ;==>_SQLite_SetTimeout  
×
×
  • Create New...