the error message is nonsensical. u need to be checking ErrorLevel and A_LastError after the DllCall and only then can u determine what the nature of the error is, not outright assert its because a file couldnt be found
Re: [Class] SQLiteDB - Update on 2019-12-12
Posted: 03 May 2021, 13:37
by pmobin
Thanks a million Hoppfrosch, I wouldn't have guessed that in a million years. I reinstalled ahk and it got rid of the error. Now onwards with the sqlite adventure. : )
Re: [Class] SQLiteDB - Update on 2019-12-12
Posted: 29 Sep 2021, 20:23
by 20170201225639
Thanks just me for the great class I've been using since forever.
I found what seems to me to be a minor problem. I was able to successfully execute a query in DB Browser for SQLite but Class_SQLiteDB kept returning nothing via GetTable. Then after some investigation I finally realized that the cause is a rather trivial one. The query I used is a recursive query starting with "WITH" (to get all nodes directly or indirectly connected to a given node in a directed graph), and GetTable judged this not to be a valid query because it doesn't start with SELECT or PRAGMA
SalesDB := New SQLiteDB
SalesDB.OpenDB("C:\Users\Desktop\AHK Scripts\SalesData.db")
arg:="SELECT * FROM CustomerFollowUp"
ExportDB2Csv(SalesDB,arg,"OutputFile.csv")
ExportDB2Csv(MyDB,arg,DestFile,OverWrite:=0) ; arg is for the SELECT statement; set OverWrite to 1 to Overwrite the Destination file, or 0 to append
{
; Last Updated - 2022-01-05, 15:39:33 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1064&p=435741#p435741
If !MyDB.GetTable(arg, objTable)
{
MsgBox, % "SQLite GETTABLE Error`n`nMessage: " . MyDB.ErrorMsg . "`nCode: " . MyDB.ErrorCode . "`nQuery: " . arg ; error message
return
}
For i,v in objTable.ColumnNames
{
If (i=1)
line:= """" v """"
Else
line.= ",""" v """"
}
Table:=line
For i,v in objTable.Rows
{
line:=""
For p,q in v
{
If (p=1)
line:= """" q """"
Else
line.= ",""" q """"
}
Table.="`n" line
}
if (OverWrite=1)
FileDelete, % DestFile
FileAppend,% Table,% DestFile
}
Re: [Class] SQLiteDB - Update on 2021-10-10
Posted: 08 Mar 2022, 11:51
by Drugwash
Most likely my fault but can't seem to be able to add more than a blob to a row. Maybe I ate stupid mushrooms or something.
Anyway, what I'm trying to do is parse a load of image files in a folder and add them to a database based on an ascending index that can be identical for two or more files. Everything works fine for only one file per index, but when two or more files use the same index adding another file (blob) to a row will nullify the preceding one.
I tried using the Prepare statement as per the sample script. In desperation even loaded all filenames in a variable and sorted it in case directly looping through the folder may have provided non-sequenced indexes. All to no avail. All I managed lately was to add two separate entries for the same index, which is not useful for the purpose of the script. Any idea where I could be going so wrong or what would be the correct approach?
Nevermind, finally figured it out. It's about the Step and Reset position.
Re: [Class] SQLiteDB - Update on 2021-10-10
Posted: 14 Mar 2022, 11:28
by pmobin
Hello all, quick question, is there a "select" functionality in SQLiteDB? I mean can you switch between two or more tables to do next() commands and it gives you the next of the selected table? This is very useful when you are scanning one table and at each row you do something with the other table like next, search for something, update etc. and when you select back to the first table it is siting where it was prior to the switch. This is to save the state of each table pointers per selected table. If you know foxpro that would be the SELECT SOMETABLE function. BTW I have already implemented the foxpro skip in ahk which goes to the next record and binds all table fields to byref vars with same fieldnames. Those vars will then be available as locals to the calling function. It's made my code a lot cleaner. And thanks for creating this GREAT library.
Hey there @just me, finally getting around to trying prepared statements. Having some trouble with what seems to be an error binding (specifically) Text values.
The methods do not throw an error and the parameters insert as an empty string instead of the expected value.
#include <class_sqlitedb>
db := new sqlitedb
db.opendb(a_scriptdir "\dummy.db")
If !db.exec("CREATE TABLE IF NOT EXISTS tweets(id,user,msg);")
msgbox % "table create error"
;if !db.exec("DELETE FROM TWEETS;")
;msgbox % "delete error"
if !db.prepare("INSERT OR IGNORE INTO tweets(id,user,msg) VALUES(?,?,?);",prepareSt)
msgbox % "prepare error"
;generate unique set of parameters across multiple tests
basis := a_tickcount
If !prepareSt.bind(1, "Int", basis) ;works
msgbox % "error binding id"
;slot 2 works with Int, issue is not position related
;If !prepareSt.bind(2, "Int", (basis + 1))
;msgbox % "error binding user"
If !prepareSt.bind(2, "Text", "user-" basis) ;inserts blank string (not a NULL)
msgbox % "error binding user"
If !prepareSt.bind(3, "Text", "msg-" basis) ;same as above
msgbox % "error binding msg"
If !prepareSt.step() ;works
msgbox % "error on step"
If !prepareSt.reset() ;works
msgbox % "error on reset"
sample results (plus a couple runs configured to insert nulls so you see the difference):
Ints do work and I have not tried Blobs.
Thanks in advance!
Re: [Class] SQLiteDB - Update on 2021-10-10
Posted: 17 Sep 2022, 21:46
by Drugwash
At line 401 in Class_SQLiteDB.ahk you have to remove the ByRef in the function call so it would become This._DB._StrToUTF8(Param3, UTF8). After that it'll work.
The issue has been opened on GitHub as a PR but there has been no reaction so far from the developer.
At line 401 in Class_SQLiteDB.ahk you have to remove the ByRef in the function call so it would become This._DB._StrToUTF8(Param3, UTF8). After that it'll work.
That worked! Thanks so much!
Re: [Class] SQLiteDB - Update on 2021-10-10
Posted: 17 Sep 2022, 22:19
by Drugwash
You're welcome.
Re: [Class] SQLiteDB - Update on 2022-09-18
Posted: 18 Sep 2022, 03:39
by just me
Bug fixed, thx @Drugwash.
Re: [Class] SQLiteDB - Update on 2022-09-18
Posted: 18 Sep 2022, 03:48
by Drugwash
You're welcome. BTW, that's not my PR - just happened to notice it as I follow the repository.
Re: [Class] SQLiteDB - Update on 2022-09-18
Posted: 19 Sep 2022, 18:20
by Qriist
Another bug report for you @just me. This one is super arcane, too.
The DLL call to set ST.ParamCount on Line 922 is passing the wrong variable. Instead of This._Handle it should be Stmt.
explanation with screenshots
Your .Bind() logic never caught it because the pointer address is normally way above anything a parameter index might be.
image.png (31.77 KiB) Viewed 3144 times
image.png (22.7 KiB) Viewed 3144 times
It wasn't until I was using the prepared statement methods in a multithreaded enviornment that I got an error because the ostensible value was negative.
image.png (24.37 KiB) Viewed 3144 times
Huge shoutout to @CloakerSmoker and @ShatterCoder for helping me track down the bug!