Skip to content

storage_t::last_insert_rowid

Yevgeniy Zakharov edited this page Mar 30, 2017 · 3 revisions
int64 last_insert_rowid();

Returns last_insert_rowid() function call result.

Return value

ID of row inserted last time. Return type int64 is defined like this typedef sqlite_int64 int64; in sqlite_orm namespace.

Example

#include <iostream>

using std::cout;
using std::endl;

struct UserType {
    int id;
    std::string name;
    std::string comment;
};

using namespace sqlite_orm;
auto storage = make_storage("db.sqlite",
                            make_table("user_types",
                                       make_column("id",
                                                   &UserType::id,
                                                   autoincrement(),
                                                   primary_key()),
                                       make_column("name",
                                                   &UserType::name),
                                       make_column("comment",
                                                   &UserType::comment,
                                                   default_value("user"))));
UserType myObject{1, "admin"};
storage.transaction([&]{
    storage.insert(myObject);
    cout << "last_insert_rowid = " << storage.last_insert_rowid() << endl;
    return true;
});

External links:

last_insert_rowid on sqlite.org

Clone this wiki locally