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 );
This function returns the ID of the row inserted with 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 row ID.
If the QDB_OPTION_LAST_INSERT_ROWID option is enabled, the qdb_last_insert_rowid() function first looks in the result argument; if this pointer is non-NULL, the information for the statement that produced the result is returned. If result is NULL or QDB_OPTION_LAST_INSERT_ROWID is disabled, the function instead queries the specified database handle (db) and returns the information about the last executed statement.
If this function returns 0, check errno to make sure that it's EOK, which indicates 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. An errno value other than EOK means that there was an error with the request.
If an INSERT occurs within a trigger, then the ID of the inserted row is returned so long as the trigger is running when the function is called. If the trigger has already terminated, the function instead returns the ID of the last row inserted before the trigger fired.
QNX Neutrino
Safety: | Â |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |