1.Dd March 11, 2017 2.Dt SQLITE3_LAST_INSERT_ROWID 3 3.Os 4.Sh NAME 5.Nm sqlite3_last_insert_rowid 6.Nd Last Insert Rowid 7.Sh SYNOPSIS 8.Ft sqlite3_int64 9.Fo sqlite3_last_insert_rowid 10.Fa "sqlite3*" 11.Fc 12.Sh DESCRIPTION 13Each entry in most SQLite tables (except for WITHOUT ROWID 14tables) has a unique 64-bit signed integer key called the "rowid". 15The rowid is always available as an undeclared column named ROWID, 16OID, or _ROWID_ as long as those names are not also used by explicitly 17declared columns. 18If the table has a column of type INTEGER PRIMARY KEY 19then that column is another alias for the rowid. 20.Pp 21The sqlite3_last_insert_rowid(D) interface returns the rowid of 22the most recent successful INSERT into a rowid table or virtual table 23on database connection D. 24Inserts into WITHOUT ROWID tables are not recorded. 25If no successful INSERTs into rowid tables have ever occurred 26on the database connection D, then sqlite3_last_insert_rowid(D) returns 27zero. 28.Pp 29If an INSERT occurs within a trigger or within a virtual table 30method, then this routine will return the rowid of the inserted 31row as long as the trigger or virtual table method is running. 32But once the trigger or virtual table method ends, the value returned 33by this routine reverts to what it was before the trigger or virtual 34table method began. 35.Pp 36An INSERT that fails due to a constraint violation is not a successful 37INSERT and does not change the value returned by this routine. 38Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, and INSERT 39OR ABORT make no changes to the return value of this routine when their 40insertion fails. 41When INSERT OR REPLACE encounters a constraint violation, it does not 42fail. 43The INSERT continues to completion after deleting rows that caused 44the constraint problem so INSERT OR REPLACE will always change the 45return value of this interface. 46.Pp 47For the purposes of this routine, an INSERT is considered to 48be successful even if it is subsequently rolled back. 49.Pp 50This function is accessible to SQL statements via the last_insert_rowid() SQL function. 51.Pp 52If a separate thread performs a new INSERT on the same database 53connection while the sqlite3_last_insert_rowid() 54function is running and thus changes the last insert rowid, then 55the value returned by sqlite3_last_insert_rowid() 56is unpredictable and might not equal either the old or the new last 57insert rowid. 58.Sh SEE ALSO 59.Xr sqlite3_last_insert_rowid 3 60