Return the primary key of the last inserted row
#include <qdb/qdb.h> uint64_t qdb_last_insert_rowid( qdb_hdt_t *db, qdb_result_t *result );
qdb
This function returns the row ID of the last INSERT statement. Each entry in a QDB table has a unique integer key called the row ID. This key is always available as an undeclared column named ROWID, OID, or _ROWID_. If the table has a column of type INTEGER PRIMARY KEY, then that column is an alias for the rowid.
The qdb_last_insert_rowid() function first looks in result (if the QDB_OPTION_LAST_INSERT_ROWID option is enabled), returning the information for the statement that produced the result. If result is NULL or QDB_OPTION_LAST_INSERT_ROWID is disabled, the function queries the database handle db and returns the information about the last executed statement.
If this function returns 0, check errno to make sure that it is EOK, indicating that no rows were inserted (you should set errno to 0 before calling this function if you want to distinguish between an error and 0 rows). If errno is set, there was an error with the request.
If an INSERT occurs within a trigger, then the row ID of the inserted row is returned by this function as long as the trigger is running. When the trigger terminates, the function will return the last value inserted before the trigger fired.
QNX Neutrino
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |