Function Reference


_SQLite_GetTable2d

Passes out a 2Dimensional array containing column names and data of executed query

#include <SQLite.au3>
_SQLite_GetTable2d ( $hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns [, $iCharSize = -1 [, $bSwichDimensions = False]] )

Parameters

$hDB An Open Database, Use -1 To use Last Opened Database
$sSQL SQL Statement to be executed
$aResult Passes out the result
$iRows Passes out the amount of 'data' Rows
$iColumns Passes out the amount of columns
$iCharSize [optional] Specifies the maximal size of a data field
$bSwichDimensions [optional] Switches dimensions of $aResult

Return Value

Success: $SQLITE_OK.
Failure: a value that can be compared against $SQLITE_* constants.
@error: -1 - SQLite reported an error (Check Return value)
1 - Error Calling _SQLite_Query()
2 - Error calling SQLite API 'sqlite3_free_table'
3 - Call prevented by SafeMode
4 - Abort, Interrupt or @error set by Callback (@extended set to SQLite error)

Remarks

The number of values inserted into $aResult will be (($iRows) + 1) * ($iColumns).
A NULL will be returned as Numeric 0.
This function uses more memory than _SQLite_Query() / _SQLite_Fetch*()... but it's faster.
If you do not need a result (or if there will be none) consider using SQLite_Exec().

Related

_SQLite_Display2DResult, _SQLite_Exec, _SQLite_GetTable, _SQLite_Query

Example

#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup()
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!")
    Exit -1
EndIf
ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)
_SQLite_Open() ; Open a :memory: database
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!")
    Exit -1
EndIf

; Example Table
; Name        | Age
; -----------------------
; Alice       | 43
; Bob         | 28
; Cindy       | 21

If Not _SQLite_Exec(-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

; Query
$iRval = _SQLite_GetTable2d(-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then
    _SQLite_Display2DResult($aResult)

    ; $aResult looks like this:
    ; Name   Age
    ; Alice  43
    ; Bob    28
    ; Cindy  21
    ; If the dimensions would be switched in _SQLite_GetTable2d the result would look like this:
    ; Name  Alice  Bob  Cindy
    ; Age   43     28   21

Else
    MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
EndIf

_SQLite_Close()
_SQLite_Shutdown()