diff --git a/src/core/database.cpp b/src/core/database.cpp index 42603ad..a80cf0d 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -9,16 +9,20 @@ Database::Database(const std::string& dbname) : db_(nullptr) if (errCode) { throw std::runtime_error("Could not open database file."); } - exec("PRAGMA foreign_key = 1"); + sqlite3_db_config(db_, SQLITE_DBCONFIG_ENABLE_FKEY); } Database::~Database() { sqlite3_close(db_); } void Database::exec(const std::string& sql) { - const int errCode = sqlite3_exec(db_, sql.c_str(), nullptr, nullptr, nullptr); + char* errMsg; + const int errCode = sqlite3_exec(db_, sql.c_str(), nullptr, nullptr, &errMsg); if (errCode) { - throw std::runtime_error("Error in SQL execution."); + std::string errMsgString(errMsg); // Make a C++ string of the errMsg, so that we can call + // sqlite3_free() before throwing the exception + sqlite3_free(errMsg); + throw std::runtime_error("Error in SQL execution: " + errMsgString); } }