All Manuals > LispWorks User Guide and Reference Manual > 47 The SQL Package

NextPrevUpTopContentsIndex

sqlite-last-insert-rowid

Function
Summary

Return the ROWID of the last inserted row in a SQLite database.

Package

sql

Signature

sqlite-last-insert-rowid &key database => rowid

Arguments

database

A SQLite database.

Values

rowid

An integer.

Description

The function sqlite-last-insert-rowid returns the ROWID of the last row that was inserted in database, or 0 if none.

Notes

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.

See also

sqlite-open-blob


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex