SQLite System Functions
SQLite system functions report information about the current SQLite connection, library build, and stored values. Unlike server databases, SQLite is embedded in the application, so sqlite_version() reports the SQLite library version rather than a database server version.
| Task | Function |
|---|---|
| Check the SQLite library version | sqlite_version() |
| Identify a value’s storage class | typeof() |
| Count rows changed by the most recent INSERT, UPDATE, or DELETE | changes() |
| Count rows changed on this connection since it opened | total_changes() |
| Read the last inserted rowid on this connection | last_insert_rowid() |
| Inspect SQLite compilation options | sqlite_compileoption_get() and sqlite_compileoption_used() |
| Identify the exact SQLite source build | sqlite_source_id() |
Check the SQLite version and a value’s type
SELECT sqlite_version() AS library_version,
typeof(42) AS storage_class;
The version depends on the SQLite library used to run the query; storage_class is integer.
Count changed rows
CREATE TABLE demo (id INTEGER PRIMARY KEY);
INSERT INTO demo (id) VALUES (1), (2);
SELECT changes() AS last_statement_rows,
total_changes() AS connection_rows;
On a new connection, the result is 2 for both columns. changes() reflects the most recent completed data-changing statement; total_changes() accumulates changes on the connection, so results can differ after further writes.
Run these examples in the SQLite Playground without connecting to a server. For column declarations and dynamic typing, see SQLite storage classes and type affinity.
-
changes
The SQLite changes() function returns the number of rows affected by the lastINSERT,UPDATE, orDELETEstatement. -
last_insert_rowid
The SQLite last_insert_rowid() function returns the ROWID of the last row inserted into the database from the connection currently calling this function. -
sqlite_compileoption_get
The SQLite sqlite_compileoption_get() function returns compile-time options for the specified location used to build SQLite. -
sqlite_compileoption_used
The SQLite sqlite_compileoption_used() function checks whether SQLite was built with the specified compile-time option. -
sqlite_source_id
The SQLite sqlite_source_id() function a string representing the version of the source code used to build the current SQLite library. -
sqlite_version
The SQLite sqlite_version() function returns the version of the current SQLite server. -
total_changes
The SQLite total_changes() returns the total number of rows affected by theINSERT,UPDATE, andDELETEstatements since the current connection was established. -
typeof
The SQLite typeof() function returns the data type of the parameter, it will return one of these stringsnull,integer,real,text, andblob.