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 );


A pointer to the database handle. You can pass NULL for this argument if you provide a value for result and you enable the QDB_OPTION_LAST_INSERT_ROWID option when calling qdb_setoption(). Note that this option is enabled by default.
A pointer to the result set that you want to query. If you pass in NULL, the function queries the server connection db for the last qdb_statement() call.




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.


The integer primary key of the last inserted row.
An error occurred (errno is set) or no rows were inserted.


QNX Neutrino

Interrupt handler No
Signal handler No
Thread Yes