MCPcopy Create free account
hub / github.com/bcndev/bytecoin / open_check_create

Method open_check_create

src/platform/DBsqlite3.cpp:18–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18void sqlite::Dbi::open_check_create(OpenMode open_mode, const std::string &fp, bool *created) {
19 full_path = fp;
20 sqlite::check(sqlite3_open_v2(platform::expand_path(full_path).c_str(),
21 &handle,
22 open_mode == OpenMode::O_READ_EXISTING
23 ? SQLITE_OPEN_READONLY
24 : open_mode == OpenMode::O_OPEN_EXISTING ? SQLITE_OPEN_READWRITE
25 : (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE),
26 nullptr),
27 "sqlite3_open ");
28 invariant(open_mode != OpenMode::O_CREATE_ALWAYS, "sqlite database does not support clearing existing data");
29 if (open_mode == OpenMode::O_READ_EXISTING)
30 exec("BEGIN TRANSACTION",
31 "modifying database impossible. Disk read-only or database used by other running instance?");
32 else
33 exec("BEGIN IMMEDIATE TRANSACTION",
34 "modifying database impossible. Disk read-only or database used by other running instance?");
35 sqlite::Stmt stmt_get_tables;
36 stmt_get_tables.prepare(*this, "SELECT name FROM sqlite_master WHERE type = 'table'");
37 *created = !stmt_get_tables.step();
38 if (open_mode == OpenMode::O_CREATE_NEW && !*created)
39 throw ErrorDBExists("sqlite database " + full_path + " already exists and will not be overwritten");
40 sqlite::check(sqlite3_busy_timeout(handle, 5000), "sqlite3_busy_timeout"); // ms
41}
42
43void sqlite::Dbi::exec(const char *statement, const char *err_msg) {
44 auto rc = sqlite3_exec(handle, statement, nullptr, nullptr, nullptr);

Callers 3

DBsqliteKVMethod · 0.80
is_sqliteMethod · 0.80
WalletHDsqliteMethod · 0.80

Calls 4

expand_pathFunction · 0.85
ErrorDBExistsClass · 0.85
stepMethod · 0.80
prepareMethod · 0.45

Tested by

no test coverage detected