Opened 18 years ago
Closed 18 years ago
#190 closed Bug (Duplicate)
_SQLite_GetTable2d crashes script if column field is null or unset
| Reported by: | mims.michael@… | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.2.10.0 | Severity: | |
| Keywords: | SQLite, _SQLite_GetTable2d, __SQLite_szStringRead | Cc: |
Description
I have incurred a fatal error that occurs during the call to _SQLite_GetTable2d. The error occurs when I have a null or unset (not sure what the SQLite terminology is) value in one of the columns of a row of data. The following script will produce the error
#include <SQLite.au3>
#include <SQLite.dll.au3>
Local $hQuery, $aResult, $iRows, $iColumns
_SQLite_Startup ()
_SQLite_Open () ; open :memory: Database
_SQLite_Exec (-1, "CREATE TABLE aTest (a,b,c);")
_SQLite_Exec (-1, "INSERT INTO aTest(a,b,c) VALUES ('no','columns','null');")
_SQLite_Exec (-1, "INSERT INTO aTest(a,c) VALUES ('missing','b');")
If _SQLite_GetTable2d(-1, "SELECT ROWID,* FROM aTest;", $aResult, $iRows, $iColumns) = $SQLITE_OK Then
_SQLite_Display2DResult($aResult)
EndIf
_SQLite_Exec (-1, "DROP TABLE aTest;")
_SQLite_Close ()
_SQLite_Shutdown ()
If you remove the line:
_SQLite_Exec (-1, "INSERT INTO aTest(a,c) VALUES ('missing','b');")
the script executes as expected.
I narrowed the error down to an internal function call (_SQLite_szStringRead) within the _SQLite_GetTable2d function:
Func __SQLite_szStringRead($iszPtr, $iLen = -1)
Local $aStrLen, $vszString
If $iszPtr < 1 Then Return ""
If $iLen < 1 Then
If $g_avSafeMode_SQLite[3] < 1 Then $g_avSafeMode_SQLite[3] = DllOpen("msvcrt.dll")
$aStrLen = DllCall($g_avSafeMode_SQLite[3], "int:cdecl", "strlen", "ptr", $iszPtr)
If @error Then Return SetError(1, 0, "")
$iLen = $aStrLen[0] + 1
EndIf
$vszString = DllStructCreate("char[" & $iLen & "]", $iszPtr)
If @error Then Return SetError(2, 0, "")
Return SetError(0, $iLen, DllStructGetData($vszString, 1))
EndFunc ;==>__SQLite_szStringRead
In the case of a null or unset value, the line:
If $iszPtr < 1 Then Return ""
should evaluate as true as the value of $iszPtr is always 0. However, this is not the case and I have found that changing the line to:
If $iszPtr < 1 Or $iszPtr = 0 Then Return ""
will fix the problem.
Attachments (0)
Change History (1)
comment:1 Changed 18 years ago by Jpm
- Resolution set to Duplicate
- Status changed from new to closed
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.

already solved in Beta since december