Nice thing. Thank you.
Maybe I'm abit blind and didn't find that info, but How can I insert random parced html page code? I have some errors trying to. (parcing it from chrome via chrome.ahk)
texthtml := PageInst.Evaluate("document.body.innerHTML;").Value ;I will mod this into correct parts later, but for testing...
MsgBox, %texthtml% ;gives me correct text to msgbox.
SQL := "INSERT INTO toCheck VALUES('" . texthtml . "', 0);"
If !DB.Exec(SQL)
MsgBox, 16, SQLite Error, % "Msg:`t" . DB.ErrorMsg . "`nCode:`t" . DB.ErrorCode
For example I used it on this page and it gives me:
Msg: near "s": syntax error
Code: 1
PS It will be nice if I can use that saved code back as html page later.
Re: [Class] SQLiteDB - Update on 2019-07-12
Posted: 12 Nov 2019, 18:30
by kczx3
You need to escape any single quotes in the html. I’m guess there’s an apostrophe
StringReplace, texthtml, texthtml, ', ' ', All ;without space between '
Works for me
Re: [Class] SQLiteDB - Update on 2019-07-12
Posted: 11 Dec 2019, 11:39
by robodesign
Hello!
I am trying this Class and I found that if I use EscapeStr, it only returns a % whatever I feed it to, the return value is 1 [true]. Seems to be broken?...
I am trying to create a table with a large number of folders and file names.... and for some weirdly named files I get syntax error on Insert SQL exec.... therefore I assumed it is about escaping characters . I found the function in the class that ought to do it, but... something is broken. Can anyone try it also?
Silly question... Can I create and work with tables with columns other than string data type? Like integer and other data types.. I need to set /retrieve such data types in my project.
Most SQL database engines use static typing. A datatype is associated with each column in a table and only values of that particular datatype are allowed to be stored in that column. SQLite relaxes this restriction by using manifest typing. In manifest typing, the datatype is a property of the value itself, not of the column in which the value is stored. SQLite thus allows the user to store any value of any datatype into any column regardless of the declared type of that column. (There are some exceptions to this rule: An INTEGER PRIMARY KEY column may only store integers. And SQLite attempts to coerce values into the declared datatype of the column when it can.)
As far as we can tell, the SQL language specification allows the use of manifest typing. Nevertheless, most other SQL database engines are statically typed and so some people feel that the use of manifest typing is a bug in SQLite. But the authors of SQLite feel very strongly that this is a feature. The use of manifest typing in SQLite is a deliberate design decision which has proven in practice to make SQLite more reliable and easier to use, especially when used in combination with dynamically typed programming languages such as Tcl and Python.
DB := new SQLiteDB
DB.openDB(path_to_your_database)
DB.GetTable(your_sql_query, output_table)
;view entire result data including the "administrative" info
msgbox % st_printarr(output_table)
;view one row at a time
Loop, % table["RowCount"] ;iterates exactly as many times as there are rows
{
table.next(row) ;grabs the next row of data
msgbox % st_printarr(row)
}
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}
DB := new SQLiteDB
DB.openDB(path_to_your_database)
DB.GetTable(your_sql_query, output_table)
;view entire result data including the "administrative" info
msgbox % st_printarr(output_table)
;view one row at a time
Loop, % table["RowCount"] ;iterates exactly as many times as there are rows
{
table.next(row) ;grabs the next row of data
msgbox % st_printarr(row)
}
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}
I found no references to these error codes in the SQLiteDB class code or in this thread. Is this somehow available? If not, could it be in a future version of the class? It could help find the cause for an error 10.
(10) SQLITE_IOERR
The SQLITE_IOERR result code says that the operation could not finish because the operating system reported an I/O error.
A full disk drive will normally give an SQLITE_FULL error rather than an SQLITE_IOERR error.
There are many different extended result codes for I/O errors that identify the specific I/O operation that failed.
; ===================================================================================================================
; METHOD ExtErrCode Gets the extended result code in case of errors.
; Parameters: None.
; Return values: On success - Extended result code
; On failure - 0
; Remarks: Extended result code list -> https://www.sqlite.org/rescode.html#extrc
; ===================================================================================================================
ExtErrCode() {
If !(This._Handle)
Return 0
Return DllCall("SQLite3.dll\sqlite3_extended_errcode", "Ptr", This._Handle, "Cdecl Int")
}
Re: [Class] SQLiteDB - Update on 2019-12-12
Posted: 10 Nov 2020, 15:43
by JnLlnd
Thanks just me for the quick reply.
The error occurred on the system of one of my client. I could not test this new code with a "real life" error right now. But I'll add it in a future release of my app and we'll see if user reporting the a similar error would have more info from the ExtErrCode() function.
For now, looking at other diag info I got from the client, it really looks like an error caused by a disk full.
I am using multiple instances of the same script, all open the database using Read access only. Any ideas how to go about this? I am trying to collect tons of data from a given table, all in the same database, using multiple scripts [instances] ...
When I use Free() from _RecordSet() class like this: RecordSet.Free()... The various instances I spawn crash. The error message indicates the line of the already mentioned DLL Call.
Re: [Class] SQLiteDB - Update on 2019-12-12
Posted: 20 Nov 2020, 19:52
by kczx3
It doesn't crash when just a single instance of your script is running?
I don’t think that applies. First, connections to the same database by different AHK processes is not the same as multiple connections across threads. Second, it looks as though SQLite is compiled in a thread safe manner by default.