Return the ROWID of the last inserted row in a SQLite database.
sql
sqlite-last-insert-rowid &key database => rowid
database⇩ |
A SQLite database. |
rowid⇩ |
An integer. |
The function sqlite-last-insert-rowid
returns the ROWID of the last row that was inserted in database, or 0 if none.
sqlite-last-insert-rowid
is not thread-safe, and you will need to ensure that no other thread inserts rows into database in parallel to the insertion of the row and calling sqlite-last-insert-rowid
.
The result rowid is useful when you want to later access a BLOB in the row using sqlite-open-blob.
ROWIDs in SQLite are described in the SQLite documentation: "ROWIDs and the INTEGER PRIMARY KEY" in "CREATE TABLE" https://www.sqlite.org/lang_createtable.html#rowid.
Because sqlite-last-insert-rowid
is called on the database connection, any row insertion into database affects it, even if it is not in the same table or even not the same file (if another file is attached to the connection using the "ATTACH DATABASE" statement). Therefore, there must not be another insertion into database in parallel to the sequence of insertion and calling sqlite-last-insert-rowid
.
These restrictions mirror the underlying limitation of the C function sqlite3_last_insert_rowid
.
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:56