Function Reference

_SQLite_LastInsertRowID

直近にデータベースに挿入された行IDを返します。

#include <SQLite.au3>
_SQLite_LastInsertRowID ( [ $hDB ] )

 

パラメータ

$hDB [オプション] 開かれているデータベース。最後に開かれたデータベースを使用する場合-1を使用

 

返し値

成功: 行IDを返します
失敗: 0を返します
@error: 1 - SQLite API 'sqlite3_last_insert_rowid'の呼び出しエラー
2 - SafeModeによって呼び出しが阻止されました

 

注意

なし。

 

関連

None.

 


#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

; _SQLite_Exec()と_SQLite_Execute()はまったく同じ
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 ())

; _SQLite_LastInsertRowID()はCindyの行を返す
MsgBox( 0, "_SQLite_LastInsertRowID()", _SQLite_LastInsertRowID() )

; クエリ
$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 ()