KSQL_LASTID(3) Library Functions Manual KSQL_LASTID(3)

ksql_lastid
get the last insertion row identifier

library “ksql”

#include <sys/types.h>
#include <stdint.h>
#include <ksql.h>
enum ksqlc
ksql_lastid(struct ksql *sql, int64_t *id);

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

sqlite3_last_insert_rowid(3)
April 20, 2018 OpenBSD 6.4