传递一个 2 维数组,其中包含执行查询的列名称和数据
#include <SQLite.au3>
_SQLite_GetTable2d ( $hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns [, $iCharSize = -1 [, $fSwichDimensions = False ]] )
$hDB | 打开的数据库,如为 -1, 则使用最后打开的数据库 |
$sSQL | 要执行的语句 |
$aResult | 传递出的结果 |
$iRows | 传递出的数据行数 |
$iColumns | 传递出的列数 |
$iCharSize | [可选参数] 指定数据字段的最大尺寸 |
$fSwichDimensions | [可选参数] 切换 $aResult 规模 |
成功: | 返回 $SQLITE_OK |
失败: | 返回值可能违反 $SQLITE_* 常量 |
@error: | -1 - SQLite 报告错误 (检查返回值) |
1 - 错误调用 _SQLite_Query | |
2 - 错误调用 SQLite API 'sqlite3_free_table' | |
3 - 调用被安全模式阻止 | |
4 - 中止,中断或由回调设置的 @error (@extended 设置为 SQLite 错误) |
#include <SQLite.au3>
#include <SQLite.dll.au3>
Local $aResult, $iRows, $iColumns, $iRval
_SQLite_Startup()
If @error Then
MsgBox(16, "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(16, "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(16, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
MsgBox(16, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
MsgBox(16, "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(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
EndIf
_SQLite_Close()
_SQLite_Shutdown()