diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-19 11:55:55 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-19 13:39:18 -0800 |
commit | dbfa932ed1e10c4f70639f138132f117c4b98152 (patch) | |
tree | 59edf15fb9ed3db90c05b6eb0cbaef5fd149eb74 /platform/default | |
parent | 6709bdcacd5a45a10b554f3f225206c9494e5e43 (diff) | |
download | qtlocation-mapboxgl-dbfa932ed1e10c4f70639f138132f117c4b98152.tar.gz |
[core] Eliminate macros in sqlite3.cpp
Diffstat (limited to 'platform/default')
-rw-r--r-- | platform/default/sqlite3.cpp | 46 | ||||
-rw-r--r-- | platform/default/sqlite3.hpp | 2 |
2 files changed, 22 insertions, 26 deletions
diff --git a/platform/default/sqlite3.cpp b/platform/default/sqlite3.cpp index 742c7e3217..7e8a56f7f9 100644 --- a/platform/default/sqlite3.cpp +++ b/platform/default/sqlite3.cpp @@ -80,16 +80,6 @@ Statement::Statement(sqlite3 *db, const char *sql) { } } -#define CHECK_SQLITE_OK_STMT(err, stmt) \ - if (err != SQLITE_OK) { \ - throw Exception { err, sqlite3_errmsg(sqlite3_db_handle(stmt)) }; \ - } - -#define CHECK_SQLITE_OK(err) \ - if (err != SQLITE_OK) { \ - throw Exception { err, sqlite3_errstr(err) }; \ - } - Statement::Statement(Statement &&other) { *this = std::move(other); } @@ -109,38 +99,41 @@ Statement::operator bool() const { return stmt != nullptr; } -#define BIND_3(type, value, stmt) \ - assert(stmt); \ - const int err = sqlite3_bind_##type(stmt, offset, value); \ - CHECK_SQLITE_OK_STMT(err, stmt) - -#define BIND_5(type, value, length, param, stmt) \ - assert(stmt); \ - const int err = sqlite3_bind_##type(stmt, offset, value, length, param); \ - CHECK_SQLITE_OK_STMT(err, stmt) +void Statement::check(int err) { + if (err != SQLITE_OK) { + throw Exception { err, sqlite3_errmsg(sqlite3_db_handle(stmt)) }; + } +} template <> void Statement::bind(int offset, int value) { - BIND_3(int, value, stmt) + assert(stmt); + check(sqlite3_bind_int(stmt, offset, value)); } template <> void Statement::bind(int offset, int64_t value) { - BIND_3(int64, value, stmt) + assert(stmt); + check(sqlite3_bind_int64(stmt, offset, value)); } template <> void Statement::bind(int offset, double value) { - BIND_3(double, value, stmt) + assert(stmt); + check(sqlite3_bind_double(stmt, offset, value)); } template <> void Statement::bind(int offset, bool value) { - BIND_3(int, value, stmt) + assert(stmt); + check(sqlite3_bind_int(stmt, offset, value)); } template <> void Statement::bind(int offset, const char *value) { - BIND_5(text, value, -1, nullptr, stmt) + assert(stmt); + check(sqlite3_bind_text(stmt, offset, value, -1, SQLITE_STATIC)); } void Statement::bind(int offset, const std::string &value, bool retain) { - BIND_5(blob, value.data(), int(value.size()), retain ? SQLITE_TRANSIENT : SQLITE_STATIC, stmt) + assert(stmt); + check(sqlite3_bind_blob(stmt, offset, value.data(), int(value.size()), + retain ? SQLITE_TRANSIENT : SQLITE_STATIC)); } bool Statement::run() { @@ -150,8 +143,9 @@ bool Statement::run() { return false; } else if (err == SQLITE_ROW) { return true; + } else if (err != SQLITE_OK) { + throw Exception { err, sqlite3_errmsg(sqlite3_db_handle(stmt)) }; } else { - CHECK_SQLITE_OK_STMT(err, stmt) return false; } } diff --git a/platform/default/sqlite3.hpp b/platform/default/sqlite3.hpp index 1cad56f918..29e8967db3 100644 --- a/platform/default/sqlite3.hpp +++ b/platform/default/sqlite3.hpp @@ -52,6 +52,8 @@ private: Statement(const Statement &) = delete; Statement &operator=(const Statement &) = delete; + void check(int err); + public: Statement(sqlite3 *db, const char *sql); Statement(Statement &&); |