From 9446b871f83c7ec20689c2130da23e856208746a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 29 Aug 2011 17:46:51 +0000 Subject: [PATCH] sqlite: fix the ifdef checking so that we actually enable sqlite_open_v2 usages, and also pass the READ mode to avoid undefined behavior - re-closes #797 --- plugins/input/sqlite/sqlite_types.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/input/sqlite/sqlite_types.hpp b/plugins/input/sqlite/sqlite_types.hpp index ffa9daadf..2e3f6be78 100644 --- a/plugins/input/sqlite/sqlite_types.hpp +++ b/plugins/input/sqlite/sqlite_types.hpp @@ -132,11 +132,19 @@ public: sqlite_connection (const std::string& file) : db_(0) { - #ifdef sqlite3_open_v2 - sqlite3_enable_shared_cache(1); - if (sqlite3_open_v2 (file.c_str(), &db_, SQLITE_OPEN_NOMUTEX|SQLITE_OPEN_SHAREDCACHE, 0)) + // sqlite3_open_v2 is available earlier but + // shared cache not available until >= 3.6.18 + #if SQLITE_VERSION_NUMBER >= 3006018 + int rc = sqlite3_enable_shared_cache(1); + if (rc != SQLITE_OK) + { + throw mapnik::datasource_exception (sqlite3_errmsg (db_)); + } + + int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE; + if (sqlite3_open_v2 (file.c_str(), &db_, mode, NULL)) #else - #warning "Mapnik's sqlite plugin is compiling against an old version of sqlite that does no support sqlite3_open_v2 which may make rendering slow..." + #warning "Mapnik's sqlite plugin is compiling against an version of sqlite older than 3.6.18 which may make rendering slow..." if (sqlite3_open (file.c_str(), &db_)) #endif {