﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
190	_SQLite_GetTable2d crashes script if column field is null or unset	mims.michael@…		"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."	Bug	closed		AutoIt	3.2.10.0		Duplicate	SQLite, _SQLite_GetTable2d, __SQLite_szStringRead	
