KSQL_LASTID(3)

NAME
ksql_lastid - get the last insertion row identifier

LIBRARY
ksql

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

DESCRIPTION
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.

RETURN VALUES
The ksql_lastid function returns KSQL_NOTOPEN if the database is not open or KSQL_OK otherwise.

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

SEE ALSO
sqlite3_last_insert_rowid(3)