[core] Move SQLite logging setup to before database initialization

- Ensure that sqlite3_config() is always called before db init.
- Should only be called once, now.
- Move sqliteVersionCheck into mapbox::sqlite namespace.
This commit is contained in:
Jason Wray
2016-09-08 17:57:50 -04:00
parent 29f4204d1c
commit e26fa4dd4c
2 changed files with 10 additions and 8 deletions

View File

@@ -9,6 +9,12 @@
#include <mbgl/platform/log.hpp>
namespace mapbox {
namespace sqlite {
template <typename T>
using optional = std::experimental::optional<T>;
const static bool sqliteVersionCheck __attribute__((unused)) = []() {
if (sqlite3_libversion_number() / 1000000 != SQLITE_VERSION_NUMBER / 1000000) {
char message[96];
@@ -18,17 +24,13 @@ const static bool sqliteVersionCheck __attribute__((unused)) = []() {
throw std::runtime_error(message);
}
// Enable SQLite logging before initializing the database.
sqlite3_config(SQLITE_CONFIG_LOG, Database::errorLogCallback, nullptr);
return true;
}();
namespace mapbox {
namespace sqlite {
template <typename T>
using optional = std::experimental::optional<T>;
Database::Database(const std::string &filename, int flags) {
sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback, nullptr);
const int err = sqlite3_open_v2(filename.c_str(), &db, flags, nullptr);
if (err != SQLITE_OK) {
const auto message = sqlite3_errmsg(db);