AndyS01 Posted April 25, 2021 Posted April 25, 2021 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
TheXman Posted April 25, 2021 Posted April 25, 2021 (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 April 25, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Nine Posted April 25, 2021 Posted April 25, 2021 Your ConsoleWrite after _SQLite_Open() erases @error. So you are not testing the right result. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AndyS01 Posted April 25, 2021 Author Posted April 25, 2021 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?
AndyS01 Posted April 25, 2021 Author Posted April 25, 2021 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.
TheXman Posted April 25, 2021 Posted April 25, 2021 (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 April 25, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
AndyS01 Posted April 25, 2021 Author Posted April 25, 2021 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
TheXman Posted April 25, 2021 Posted April 25, 2021 (edited) So you probably just need to change the _SQLite_Startup() line as I suggested above. Example: expandcollapse popup#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 April 25, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
AndyS01 Posted April 28, 2021 Author Posted April 28, 2021 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. expandcollapse popup#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
AndyS01 Posted April 28, 2021 Author Posted April 28, 2021 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?
JockoDundee Posted April 28, 2021 Posted April 28, 2021 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...
jchd Posted April 28, 2021 Posted April 28, 2021 @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 hereRegExp tutorial: enough to get startedPCRE 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)
AndyS01 Posted April 28, 2021 Author Posted April 28, 2021 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".
AndyS01 Posted April 28, 2021 Author Posted April 28, 2021 Thanks, Jchd, I'll use that one. Thanks for the help everyone.🙂
jchd Posted April 28, 2021 Posted April 28, 2021 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 hereRegExp tutorial: enough to get startedPCRE 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)
JockoDundee Posted April 28, 2021 Posted April 28, 2021 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...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now