FOSSredder 0.5.0
Loading...
Searching...
No Matches
SqliteDb.cpp
Go to the documentation of this file.
1
5
7
8#include <sqlite3.h>
9#include <stdexcept>
10#include <string>
11
13
14SqliteDb::SqliteDb(const std::string& path) {
15 const int rc = sqlite3_open(path.c_str(), &db_);
16 if (rc != SQLITE_OK) {
17 std::string err;
18 if (db_) {
19 const char* msg = sqlite3_errmsg(db_);
20 if (msg) {
21 err = msg;
22 }
23 sqlite3_close(db_);
24 db_ = nullptr;
25 }
26
27 const std::string message =
28 std::string("Failed to open sqlite db '") + path + "'" +
29 (err.empty() ? std::string() : std::string(": ") + err);
30 throw std::runtime_error(message);
31 }
32
34}
35
37 if (db_) {
38 sqlite3_close(db_);
39 }
40}
Declares the lightweight SQLite connection wrapper.
Declares schema initialization and migration helpers for SQLite.
SqliteDb(const std::string &path)
Open a SQLite database at the given path.
Definition SqliteDb.cpp:14
~SqliteDb()
Close the database connection.
Definition SqliteDb.cpp:36
static void ensure(sqlite3 *db)
Ensure the database schema exists and is migrated.