-
-
Notifications
You must be signed in to change notification settings - Fork 318
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. Actually same value is returned during insert call but insert
has int
return type instead of int64
which can be not enough sometimes.
ID of row inserted last time. Return type int64
is defined like this typedef sqlite_int64 int64;
in sqlite_orm
namespace.
#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;
});