dmob Posted June 16, 2020 Share Posted June 16, 2020 (edited) So I am trying to implement an archive system of sorts for my (SQLite) DB app. I wrote a function to attach a separate (archive) DB and sync the columns with main DB. If archive DB file does not exist, create file with _SQLiteOpen then close the file (and thus connection) with SQLite_Close. This works as intended, however, after the create operation, all subsequent _SQLite_* functions returned a "Library misuse error". After a little digging I found the problem in the _SQLite_Close function: it clears the "last opened database" handle even when there still is a live DB connection open. All other functions then "think" there is no DB connection active. I hacked two functions in the UDF for a quick fix: In _SQLite_Close: Change ... $__g_hDB_SQLite = 0 __SQLite_hDel($__g_ahDBs_SQLite, $hDB) Return $iRval[0] to: $__g_hDB_SQLite = __SQLite_hDel($__g_ahDBs_SQLite, $hDB) Return $iRval[0] and in Func __SQLite_hDel changed Func __SQLite_hDel(ByRef $ahLists, $hGeneric) Local $iElement = _ArraySearch($ahLists, $hGeneric) If $iElement > 0 Then _ArrayDelete($ahLists, $iElement) EndFunc ;==>__SQLite_hDel to: Func __SQLite_hDel(ByRef $ahLists, $hGeneric) Local $iElement = _ArraySearch($ahLists, $hGeneric) If $iElement > 0 Then _ArrayDelete($ahLists, $iElement) Return $ahLists[UBound($ahLists)-1] ; Return last opened db EndIf Return 0 EndFunc ;==>__SQLite_hDel so it preserves last opened DB again. My archive function now works great I'm not sure if this should be classified as a bug, but I believe so... Hope this helps someone before Edited June 16, 2020 by dmob Add. info. TheDcoder and Musashi 2 Link to comment Share on other sites More sharing options...
TheDcoder Posted June 16, 2020 Share Posted June 16, 2020 @dmob Please create a ticket in the bug-tracker so that the devs can track this bug. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 TheDcoder, Do I have to re-explain the bug or can I just link to this topic? Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 Before creating a ticket, please post a short, stand-alone reproducer here, using the standard unmodified include. 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) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2020 Moderators Share Posted June 16, 2020 dmob, Please do as jchd has suggested. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 23 minutes ago, jchd said: Before creating a ticket, please post a short, stand-alone reproducer here, using the standard unmodified include. expandcollapse popup#include <SQLite.au3> _Example() Func _Example() Local $sSQliteDll = _SQLite_Startup() ConsoleWrite("+ SQliteDll: " & $sSQliteDll & @CRLF) ; Create DB1 Local $sFile1 = @ScriptDir & "\DB1.db" Local $oDB1 = _SQLite_Open($sFile1) ; create if not exist If @error Then ConsoleWrite("! OpenCreateErr[" & @error & "] " & _SQLite_ErrMsg() & @CRLF) Else ConsoleWrite("+ DB1 Handle: " & $oDB1 & @CRLF) EndIf ; Create DB2 Local $sFile2 = @ScriptDir & "\DB2.db" Local $oDB2 = _SQLite_Open($sFile2) ; create if not exist If @error Then ConsoleWrite("!OpenCreateErr[" & @error & "] " & _SQLite_ErrMsg() & @CRLF) Else ConsoleWrite("+ DB2 Handle: " & $oDB2 & @CRLF) EndIf ; close DB2 _SQLite_Close($oDB2) ; now attach DB2 to DB1 Local $sQry = "ATTACH '" & $sFile2 & "' AS DB2;" Local $vRet = _SQLite_Exec(-1, $sQry) If @error Then ConsoleWrite("! AttachErr[" & @error & "] " & _SQLite_ErrMsg() & @CRLF) Else ConsoleWrite("+ ATTACH Successful" & @CRLF) EndIf _SQLite_Close($oDB1) _SQLite_Shutdown() EndFunc Scite output: >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" /ErrorStdOut "D:\Scripts\......au3" + SQliteDll: sqlite3.dll + DB1 Handle: 0x00EF27D8 + DB2 Handle: 0x00EF9A28 ! AttachErr[2] Library used incorrectly >Exit code: 0 Time: 0.9089 Link to comment Share on other sites More sharing options...
TheDcoder Posted June 16, 2020 Share Posted June 16, 2020 33 minutes ago, dmob said: Do I have to re-explain the bug or can I just link to this topic? You should definitely link to the this topic, but copy-pasting your first post is also an option Also including your code sample is a must! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 I'll wait until someone actually confirms it's a bug and not old-age ... Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 The error has nothing to do with how the include works. When you create a new SQLite database, it doesn't actually exists until you really write to the DB file. That is, you need to create a DDL element (table) else the file remains empty. 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) Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 Also, the statement with attach is erroneous: you use -1 as the DB handle, which refers to the last handle used (which is $oDB2) but it's invalid after having closed the DB. Change that line into: Local $vRet = _SQLite_Exec($oDB1, $sQry) and everything should work fine. 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) Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 (edited) 14 minutes ago, jchd said: The error has nothing to do with how the include works. I beg to differ. The UDF does actually clear the last used DB handle.... 5 minutes ago, jchd said: Also, the statement with attach is erroneous: you use -1 as the DB handle, which refers to the last handle used (which is $oDB2) but it's invalid after having closed the DB. After having closed DB2, I would expect to still be able to use $oDB1, which IMHO should then be the last opened DB. Are you thus implying the UDF was designed to use only one database at a time? Edited June 16, 2020 by dmob Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 (edited) The code clears the handle passed, just as announced. 5 minutes ago, dmob said: After having closed DB2, I would expect to still be able to use $oDB1, which IMHO should then be the last opened DB. You can use $oDB1, but it isn't the last handle used! That the handle refers to an open or closed DB is irrelevant and a completely different question. Edited June 16, 2020 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 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) Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 BTW I personnally regard this use of -1 to refer to something of the past in several functions spread in various UDFs to be undue laziness and a call for bugs. Few years ago I had to actually use AutoIt for my own needs and had to handle up to 5 database connections at a time, using a large number of high-level functions. It would have been an unmanageable nightmare to try to use -1 since the "last connection used" was such a moving target. 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) Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 (edited) 27 minutes ago, jchd said: That the handle refers to an open or closed DB is irrelevant and a completely different question. 32 minutes ago, dmob said: which IMHO should then be the last opened DB I should rephrase that and say "Should then be the last opened OPEN database. I would NOT try to access a DB I just closed, nor would I expect its handle to be valid. Anyhow, if it's not a bug that's ok, but the SQLite_Close function still exhibits "unexpected & possibly unwanted behaviour". We can consider this topic closed since I have found the problem and a workaround. Edited June 16, 2020 by dmob Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2020 Moderators Share Posted June 16, 2020 dmob, Quote Should then be the last opened OPEN database That would be asking a lot of AutoIt. Throughout AutoIt "-1" is only used to denote "last created", not "last available" - which is all AutoIt should be expected to do. Expecting it to revert back through some form of GUI/control creation lineage is way beyond anything that could be reasonably expected. And I agree totally with jchd that its use is to be strongly discouraged in anything but the very simplest scripts. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 It may not be the behavior you expect, but it conforms to the specification (last used handle)... and legacy code. Skysnake 1 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) Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 (edited) 20 minutes ago, Melba23 said: Throughout AutoIt "-1" is only used to denote "last created", not "last available" That's fine with me, as I mentioned the hack I made satisfies both conditions: Once the last (when multiple DBs open) opened DB is closed, the previously opened "becomes" the last opened (__g_hDB_SQLite or -1 "points" to the last DB in the internal list of open DBs) until all DBs are closed, then the internal pointer ($__g_hDB_SQLite) is set to zero (when ALL opened DBs are closed) . Edited June 16, 2020 by dmob Link to comment Share on other sites More sharing options...
jchd Posted June 16, 2020 Share Posted June 16, 2020 You're again confusing "last open" and "last used" but it's OK if you've found a way to make things work the way you need. 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) Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 (edited) 5 minutes ago, jchd said: You're again confusing "last open" and "last used" Pardon me, English aint my first language, I'm referring to the last database in the list of OPEN Dbs. Edited June 16, 2020 by dmob Link to comment Share on other sites More sharing options...
dmob Posted June 16, 2020 Author Share Posted June 16, 2020 5 minutes ago, jchd said: found a way to make things work the way you need. Link to comment Share on other sites More sharing options...
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