ksql_lastid
—
get the last insertion row identifier
The ksql_lastid
function fills in
id with the row identifier of the last insertion. If
id is NULL
, then this does
nothing, except that the return value still indicates whether the database is
open. If no row was successfully inserted since the database
sql was opened, *id is set to 0.
The ksql_lastid
function returns
KSQL_NOTOPEN
if the database is not open or
KSQL_OK
otherwise.
The following assumes an open database sql. It inserts a
row and checks its row identifier. For brevity, it performs no error checking.
int64_t id;
struct ksqlstmt *stmt;
ksql_stmt_alloc(sql, &stmt,
"INSERT INTO test (foo) VALUES (?)", 0);
ksql_bind_int(stmt, 0, 42);
ksql_stmt_step(stmt);
ksql_lastid(sql, &id);
printf("The last rowid = %" PRId64 "\n", id);