# Function Reference

# _SQLite_Query

Prepares a SQLite Query

#include <SQLite.au3>
_SQLite_Query ( $hDB, $sSQL, ByRef $hQuery )

## Parameters

$hDB | An open database, use -1 to use last opened database
$sSQL | SQL statement to be executed
$hQuery | Passes out a query handle

## 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 API 'sqlite3_prepare16_v2' 2 - Call prevented by SafeMode

## Related

_SQLite_Exec, _SQLite_FetchData, _SQLite_FetchNames, _SQLite_GetTable, _SQLite_GetTable2D, _SQLite_QueryFinalize, _SQLite_QueryReset, _SQLite_QuerySingleRow, _SQLite_SetTimeout

## Example

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

    Local $hQuery, $aRow, $sMsg
    _SQLite_Startup()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!")
        Exit -1
    EndIf
    ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)
    _SQLite_Open() ; open :memory: Database
    _SQLite_Exec(-1, "CREATE TABLE aTest (a,b,c);") ; CREATE a Table
    _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('c','2','World');") ; INSERT Data
    _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('b','3',' ');") ; INSERT Data
    _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('a','1','Hello');") ; INSERT Data
    _SQLite_Query(-1, "SELECT c FROM aTest ORDER BY a;", $hQuery) ; the query
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $sMsg &= $aRow[0]
    WEnd
    _SQLite_Exec(-1, "DROP TABLE aTest;") ; Remove the table
    MsgBox($MB_SYSTEMMODAL, "SQLite", "Get Data using a Query : " & $sMsg)
    _SQLite_Close()
    _SQLite_Shutdown()

    ; Output:
    ; Hello World