From a3fcbb3a76e079a5485a0552ea5d35b8d6739116 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 20 May 2023 22:51:49 +0200 Subject: Use sqlite for cinema and DKDM recipient lists. --- src/lib/exceptions.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/lib/exceptions.h') diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 10231f59a..e08392689 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -34,6 +34,7 @@ extern "C" { } #include #include +#include #include #include @@ -480,4 +481,58 @@ public: }; +class SQLError : public std::runtime_error +{ +public: + SQLError(sqlite3* db, char const* s) + : std::runtime_error(get_message(db, s)) + { + _filename = get_filename(db); + } + + SQLError(sqlite3* db, int rc) + : std::runtime_error(get_message(db, rc)) + { + _filename = get_filename(db); + } + + SQLError(sqlite3* db, int rc, std::string doing) + : std::runtime_error(get_message(db, rc, doing)) + { + _filename = get_filename(db); + } + + boost::filesystem::path filename() const { + return _filename; + } + +private: + boost::filesystem::path get_filename(sqlite3* db) + { + if (auto filename = sqlite3_db_filename(db, "main")) { + return filename; + } + + return {}; + } + + std::string get_message(sqlite3* db, char const* s) + { + return String::compose("%1 (in %2)", s, get_filename(db)); + } + + std::string get_message(sqlite3* db, int rc) + { + return String::compose("%1 (in %2)", sqlite3_errstr(rc), get_filename(db)); + } + + std::string get_message(sqlite3* db, int rc, std::string doing) + { + return String::compose("%1 (while doing %2) (in %3)", sqlite3_errstr(rc), doing, get_filename(db)); + } + + boost::filesystem::path _filename; +}; + + #endif -- cgit v1.2.3