qdb_last_insert_rowid()

Return the primary key of the last inserted row

Synopsis:

#include <qdb/qdb.h>

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

Arguments:

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

Library:

qdb

Description:

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.

Returns:

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

Classification:

QNX Neutrino

Safety:  
Interrupt handler No
Signal handler No
Thread Yes