-
-
Save fundaev/74c9fdf34c2f321c7cbdec03fe6c9a39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "sqlite3.h" | |
void exec(sqlite3 *db, const char* sql) | |
{ | |
int code = sqlite3_exec(db, sql, nullptr, nullptr, nullptr); | |
if (code != SQLITE_OK) | |
throw std::runtime_error("failed to exec query: " + std::string(sql) + " : " + std::string(sqlite3_errmsg(db))); | |
} | |
void test() | |
{ | |
static const char* filename = "test.db"; | |
static const char* sql_create_table = | |
"create table t1 (id integer primary key, name text, age integer)"; | |
sqlite3 *db = nullptr; | |
sqlite3_open(filename, &db); | |
exec(db, sql_create_table); | |
exec(db, "savepoint sp1"); | |
exec(db, "insert into t1 (name, age) values('item1', 1)"); | |
exec(db, "rollback to sp1"); | |
exec(db, "savepoint sp2"); | |
exec(db, "insert into t1 (name, age) values('item2', 2)"); | |
exec(db, "release sp2"); | |
sqlite3_close(db); | |
} | |
int main(int, char**) | |
{ | |
test(); | |
std::cout << "[ ok ]" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment