diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-05-20 22:51:49 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-05-06 20:42:50 +0200 |
| commit | a3fcbb3a76e079a5485a0552ea5d35b8d6739116 (patch) | |
| tree | 58f6476b7197c0e32b5aa3d52d0859a9b04db268 /src/lib/exceptions.h | |
| parent | a4105c6e8dc83407abc9b12e80c958673c942888 (diff) | |
Use sqlite for cinema and DKDM recipient lists.
Diffstat (limited to 'src/lib/exceptions.h')
| -rw-r--r-- | src/lib/exceptions.h | 55 |
1 files changed, 55 insertions, 0 deletions
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 <boost/filesystem.hpp> #include <boost/optional.hpp> +#include <sqlite3.h> #include <cstring> #include <stdexcept> @@ -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 |
