Custom Query

Filters
 
Or
 
  
 
Columns

Show under each result:


Results (130 - 132 of 3866)

Ticket Resolution Summary Owner Reporter
#3811 Completed _SQLite_FetchData should correctly read column data according to its type Jpm matwachich@…
Description

The main problem here is that _SQLite_FetchData is reading integer types as strings.

Here is an example code showing the problem (even when isDev column is set to 0, when read it becomes "0" and is interpreted as TRUE), and the solution (a corrected version of the function):

#NoTrayIcon
#include <Crypt.au3>
#include <SQLite.au3>

_SQLite_Startup()
_SQLite_Open()

_SQLite_Exec(-1, 'CREATE TABLE test (name TEXT, age INT, rdnFlt FLOAT, isDev BOOL, md5 BLOB);')
_SQLite_Exec(-1, 'INSERT INTO test VALUES ("person 01", 30, 0.5, 0, ' & _SQLite_Encode(_Crypt_HashData("person 01", $CALG_MD5)) & '), ("person 02", 35, 1.5, 1, ' & _SQLite_Encode(_Crypt_HashData("person 02", $CALG_MD5)) & ');')

Dim $aResult, $iRows, $iCols
_SQLite_GetTable2d(-1, 'SELECT * FROM test', $aResult, $iRows, $iCols)

For $i = 1 To $iRows
	ConsoleWrite("Row " & $i & ": ")
	For $j = 0 To $iCols - 1
		ConsoleWrite($aResult[$i][$j] & " [" & VarGetType($aResult[$i][$j]) & "], ")
	Next
	ConsoleWrite("||| isDev: " & ($aResult[$i][3] ? "Yes" : "No") & @CRLF)
Next

; =============================
; now with a corrected function

ConsoleWrite(@CRLF & ">>> With the corrected function:" & @CRLF)

Dim $hQuery, $aRow, $i = 1
_SQLite_Query(-1, 'SELECT * FROM test', $hQuery)
While __mySqlite_FetchData($hQuery, $aRow) = $SQLITE_OK
	ConsoleWrite("Row " & $i & ": ")
	For $j = 0 To UBound($aRow) - 1
		ConsoleWrite($aRow[$j] & " [" & VarGetType($aRow[$j]) & "], ")
	Next
	ConsoleWrite("||| isDev: " & ($aRow[3] ? "Yes" : "No") & @CRLF)
	$i += 1
WEnd

; ==============================================================================

Func __mySqlite_FetchData($hQuery, ByRef $aRow, $bDoNotFinalize = False)
	; step to the next row
	Local $aRet = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_step", "ptr", $hQuery)
	If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error

	; check if we reached the end of the query
	If $aRet[0] <> $SQLITE_ROW Then
		If Not $bDoNotFinalize And $aRet[0] = $SQLITE_DONE Then _SQLite_QueryFinalize($hQuery)
		Return SetError(-1, 0, $aRet[0])
	EndIf

	; count columns
	Local $iColumns = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_data_count", "ptr", $hQuery)
	If @error Then Return SetError(2, @error, $SQLITE_MISUSE) ; DllCall error
	If $iColumns[0] <= 0 Then Return SetError(-1, 0, $SQLITE_DONE)
	$iColumns = $iColumns[0]

	; read data according to column type
	Dim $aRow[$iColumns]
	Local $pBlob, $iBlobSize
	For $i = 0 To $iColumns - 1
		$aRet = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_column_type", "ptr", $hQuery, "int", $i)
		If @error Then Return SetError(4, @error, $SQLITE_MISUSE) ; DllCall error

		Switch $aRet[0]
			Case $SQLITE_TYPE_NULL
				$aRow[$i] = Null
			Case $SQLITE_TYPE_INTEGER
				$aRet = DllCall($__g_hDll_SQLite, "int64:cdecl", "sqlite3_column_int64", "ptr", $hQuery, "int", $i)
				If @error Then Return SetError(8, 0, $SQLITE_MISUSE) ; DllCall error
				$aRow[$i] = $aRet[0]
			Case $SQLITE_TYPE_FLOAT
				$aRet = DllCall($__g_hDll_SQLite, "double:cdecl", "sqlite3_column_double", "ptr", $hQuery, "int", $i)
				If @error Then Return SetError(9, 0, $SQLITE_MISUSE) ; DllCall error
				$aRow[$i] = $aRet[0]
			Case $SQLITE_TYPE_BLOB
				$pBlob = DllCall($__g_hDll_SQLite, "ptr:cdecl", "sqlite3_column_blob", "ptr", $hQuery, "int", $i)
				If @error Then Return SetError(6, @error, $SQLITE_MISUSE) ; DllCall error
				$iBlobSize = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_column_bytes", "ptr", $hQuery, "int", $i)
				If @error Then Return SetError(5, @error, $SQLITE_MISUSE) ; DllCall error
				$aRow[$i] = Binary(DllStructGetData(DllStructCreate("byte[" & $iBlobSize[0] & "]", $pBlob[0]), 1))
			Case $SQLITE_TYPE_TEXT
				$aRet = DllCall($__g_hDll_SQLite, "wstr:cdecl", "sqlite3_column_text16", "ptr", $hQuery, "int", $i)
				If @error Then Return SetError(3, @error, $SQLITE_MISUSE) ; DllCall error
				$aRow[$i] = $aRet[0]
		EndSwitch
	Next

	; done
	Return $SQLITE_OK
EndFunc

Here is console output:

Row 1: person 01 [String], 30 [String], 0.5 [String], 0 [String], 0x8030B779B60EF1407533A8947D0EE209 [Binary], ||| isDev: Yes
Row 2: person 02 [String], 35 [String], 1.5 [String], 1 [String], 0x87AEFAE13874D477BA336DE19B4FF16E [Binary], ||| isDev: Yes

>>> With the corrected function:
Row 1: person 01 [String], 30 [Int64], 0.5 [Double], 0 [Int64], 0x8030B779B60EF1407533A8947D0EE209 [Binary], ||| isDev: No
Row 2: person 02 [String], 35 [Int64], 1.5 [Double], 1 [Int64], 0x87AEFAE13874D477BA336DE19B4FF16E [Binary], ||| isDev: Yes
#3810 Fixed _ArrayUnique not handling "Default" for Parameter $iIntType Jpm SEuBo
Description

_ArrayUnique is missing a line

	If $iIntType = Default Then $iIntType = $ARRAYUNIQUE_AUTO

thus returning @error = 5, when the parameter is supplied with 'Default'

Local $aArray[3] = [1, 2, 3]

; This fails:
_ArrayUnique($aArray, Default, Default, Default, Default, Default) 

; This works:
_ArrayUnique($aArray, Default, Default, Default, Default)
#3809 Fixed WinGetTitle returns blank on Windows 10 using _WinAPI_CreateWindowEx Jon Nine
Description

It is working fine under Win7. But with Win10, WinGetTitle returns blank when called with $hWnd while using _WinAPI_CreateWindowEx. If you replace $hWnd with actual title, it works. If you use "[CLASS:MyWindowClass]", it works. If you do a WinList(), it will appear in the list.

#include <WinAPIRes.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

Opt( "MustDeclareVars", 1 )

Global $bExit = False

Example()

Func Example()
        Local Const $sClass = "MyWindowClass"
        Local Const $sName = "_WinAPI_RegisterClassEx"

        ; Get module handle for the current process
        Local $hInstance = _WinAPI_GetModuleHandle( 0 )

        ; Create a class cursor
        Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW

        ; Create a class icons (large and small)
        Local $tIcons = DllStructCreate( "ptr;ptr" )
        _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 )
        Local $hIcon = DllStructGetData( $tIcons, 1 )
        Local $hIconSm = DllStructGetData( $tIcons, 2 )

        ; Create DLL callback function (window procedure)
        Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) )

        ; Create and fill $tagWNDCLASSEX structure
        Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" )
        DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) )
        DllStructSetData( $tWCEX, "Style", 0 )
        DllStructSetData( $tWCEX, "hWndProc", $pWinProc )
        DllStructSetData( $tWCEX, "ClsExtra", 0 )
        DllStructSetData( $tWCEX, "WndExtra", 0 )
        DllStructSetData( $tWCEX, "hInstance", $hInstance )
        DllStructSetData( $tWCEX, "hIcon", $hIcon )
        DllStructSetData( $tWCEX, "hCursor", $hCursor )
        DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) )
        DllStructSetData( $tWCEX, "MenuName", 0 )
        DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) )
        DllStructSetData( $tWCEX, "hIconSm", $hIconSm )
        DllStructSetData( $tWCEX, "szClassName", $sClass )

        ; Register a window class
        _WinAPI_RegisterClassEx( $tWCEX )

        ; Create a window
        Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 )
  MsgBox ($MB_SYSTEMMODAL, "", WinGetTitle($hWnd))

  ; Main msg loop
        While Sleep(10)
                If $bExit Then ExitLoop
        WEnd

        ; Unregister window class and release resources
        _WinAPI_UnregisterClass( $sClass, $hInstance )
        _WinAPI_DestroyCursor( $hCursor )
        _WinAPI_DestroyIcon( $hIcon )
        _WinAPI_DestroyIcon( $hIconSm )
EndFunc

; Window procedure
Func WinProc( $hWnd, $iMsg, $wParam, $lParam )
        Switch $iMsg
                Case $WM_CLOSE
                        $bExit = True
        EndSwitch
        Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam )
EndFunc
Note: See TracQuery for help on using queries.