Return the last inserted row primary key


#include <qdb/qdb.h>

uint64_t qdb_last_insert_rowid( qdb_hdt_t *hdl,
                                qdb_result_t *result );


A pointer to the database handle. You can pass as NULL if you provide result, and QDB_OPTION_LAST_INSERT_ROWID option has been set by qdb_setoption() (it's on by default).
A pointer to a result set you want to query. If you pass NULL, the function queries the qdb server connection hdl for the last executed qdb_statement().




Each entry in a QDB table has a unique integer key called the row ID. The row ID 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 another an alias for the rowid.

This function returns the row ID of the last INSERT. It first looks in result (if the QDB_OPTION_LAST_INSERT_ROWID option has been set by qdb_setoption()), returning the information for the statement that produced the result. If result is NULL, or QDB_OPTION_LAST_INSERT_ROWID is off, the function queries the database handle hdl 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, then there was an error with the request.

If an INSERT occurs within a trigger, then the rowid of the inserted row is returned by this function as long as the trigger is running. But once the trigger terminates, the value returned by this routine reverts to the last value inserted before the trigger fired.


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


QNX Neutrino

Interrupt handler No
Signal handler No
Thread Yes

See also:

qdb_setoption(), qdb_statement()