diff options
Diffstat (limited to 'src/database/database.cpp')
-rw-r--r-- | src/database/database.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp index cb41070..ba69d39 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -16,8 +16,18 @@ Database::IrcChannelOptionsTable Database::irc_channel_options("IrcChannelOption void Database::open(const std::string& filename) { - auto res = sqlite3_open_v2(filename.data(), &Database::db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr); - log_debug("open: ", res); + // Try to open the specified database. + // Close and replace the previous database pointer if it succeeded. If it did + // not, just leave things untouched + sqlite3* new_db; + auto res = sqlite3_open_v2(filename.data(), &new_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr); + if (res != SQLITE_OK) + { + log_error("Failed to open database file ", filename, ": ", sqlite3_errmsg(Database::db)); + throw std::runtime_error(""); + } + Database::close(); + Database::db = new_db; Database::muc_log_lines.create(Database::db); Database::muc_log_lines.upgrade(Database::db); Database::global_options.create(Database::db); |