Function Reference

_SQLite_GetTable

テーブル名と実行されたクエリのデータが格納された1次元配列を渡します。

#include <SQLite.au3>
_SQLite_GetTable ( $hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns [, $iCharSize = 64 ] )

 

パラメータ

$hDB 開かれているデータベース。最後に開かれたデータベースを使用する場合-1を使用
$sSQL 実行されるSQLステートメント
$aResult 結果が渡されます
$iRows 'データ'行数が渡されます
$iColumns 列数が渡されます
$iCharSize [オプション] データフィールドの最大サイズを指定します

 

返し値

成功: $SQLITE_OKを返します
失敗: $SQLITE_* 定数と比較可能な値を返します
@error: -1 - SQLiteがエラーを報告 (返し値を調べてください)
1 - SQLite API 'sqlite3_get_table'の呼び出しエラー
2 - SQLite API 'sqlite3_free_table'の呼び出しエラー
3 - SafeModeによって呼び出しが阻止されました
4 - SQLステートメントのUTF-8変換中のエラー

 

注意

$aResultに挿入される値の数は(($iRows) + 1) * ($iColumns)になり
この数は$aResult[0]に挿入されます。
数値の0はNULLとして返されます。
この関数は_SQlite_Query() / _SQLite_Fetch*()...よりもメモリを使用しますがより高速です。
結果を必要としない(あるいは無い)場合は_SQLite_Execute()または_SQLite_Exec()の使用を検討してください。

 

関連

_SQLite_GetTable2d, _SQLite_Exec, _SQLite_Query

 


#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <Array.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 () ; :メモリ: データベースを開く
If @error Then
    MsgBox(16, "SQLite Error", "Can't Load Database!")
    Exit - 1
EndIf

;サンプルテーブル
;   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 ())

; クエリ
$iRval = _SQLite_GetTable (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
If $iRval = $SQLITE_OK Then
;~  $aResultは次のようになる:
;~      [0]    = 8
;~      [1]    = Name
;~      [2]    = Age
;~      [3]    = Alice
;~      [4]    = 43
;~      [5]    = Bob
;~      [6]    = 28
;~      [7]    = Cindy
;~      [8]    = 21
    _ArrayDisplay($aResult, "Query Result")
Else
    MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
EndIf

_SQLite_Close ()
_SQLite_Shutdown ()