From 0f3e7ba7992b4087c2d1af7ed7264ea356953a5b Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 11 Jul 2018 08:33:40 +0200 Subject: [PATCH] small changes --- src/core/database.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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); } }