diff --git a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h index eb2a6ccdc..ac521e403 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h +++ b/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h @@ -28,8 +28,11 @@ #include "Poco/SharedPtr.h" -struct sqlite3; -struct sqlite3_stmt; +extern "C" +{ + typedef struct sqlite3 sqlite3; + typedef struct sqlite3_stmt sqlite3_stmt; +} namespace Poco { diff --git a/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h b/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h index 769d51f3e..a843b9347 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h +++ b/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h @@ -25,16 +25,16 @@ #include "Poco/Data/SQLite/Binder.h" #include "Poco/Data/AbstractSessionImpl.h" #include "Poco/SharedPtr.h" +#include "Poco/Mutex.h" -struct sqlite3; -struct sqlite3_stmt; +extern "C" +{ + typedef struct sqlite3 sqlite3; +} namespace Poco { - -class Mutex; - namespace Data { namespace SQLite { @@ -127,7 +127,8 @@ private: bool _connected; bool _isTransaction; int _timeout; - Mutex _mutex; + Poco::Mutex _mutex; + static const std::string DEFERRED_BEGIN_TRANSACTION; static const std::string COMMIT_TRANSACTION; static const std::string ABORT_TRANSACTION; diff --git a/Data/SQLite/include/Poco/Data/SQLite/Utility.h b/Data/SQLite/include/Poco/Data/SQLite/Utility.h index 305bae873..2ce1c1a95 100644 --- a/Data/SQLite/include/Poco/Data/SQLite/Utility.h +++ b/Data/SQLite/include/Poco/Data/SQLite/Utility.h @@ -28,8 +28,11 @@ #include -struct sqlite3; -struct sqlite3_stmt; +extern "C" +{ + typedef struct sqlite3 sqlite3; + typedef struct sqlite3_stmt sqlite3_stmt; +} namespace Poco { @@ -200,13 +203,6 @@ private: // // inlines // - -inline sqlite3* Utility::dbHandle(const Session& session) -{ - return reinterpret_cast(AnyCast(session.getProperty("handle"))); -} - - inline std::string Utility::lastError(const Session& session) { poco_assert_dbg ((0 == icompare(session.connector(), 0, 6, "sqlite"))); diff --git a/Data/SQLite/src/SessionImpl.cpp b/Data/SQLite/src/SessionImpl.cpp index 2440a8749..daa2da172 100644 --- a/Data/SQLite/src/SessionImpl.cpp +++ b/Data/SQLite/src/SessionImpl.cpp @@ -24,7 +24,11 @@ #include "Poco/String.h" #include "Poco/Mutex.h" #include "Poco/Data/DataException.h" +#if defined(POCO_UNBUNDLED) +#include +#else #include "sqlite3.h" +#endif #include @@ -52,7 +56,7 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout): { open(); setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT); - setProperty("handle", static_cast(_pDB)); + setProperty("handle", _pDB); addFeature("autoCommit", &SessionImpl::autoCommit, &SessionImpl::isAutoCommit); @@ -255,4 +259,14 @@ bool SessionImpl::isAutoCommit(const std::string&) } +// NOTE: Utility::dbHandle() has been moved here from Utility.cpp +// as a workaround for a failing AnyCast with Clang. +// See +// for a discussion. +sqlite3* Utility::dbHandle(const Session& session) +{ + return AnyCast(session.getProperty("handle")); +} + + } } } // namespace Poco::Data::SQLite diff --git a/Data/SQLite/src/Utility.cpp b/Data/SQLite/src/Utility.cpp index cf4593489..8bf46ee85 100644 --- a/Data/SQLite/src/Utility.cpp +++ b/Data/SQLite/src/Utility.cpp @@ -63,8 +63,6 @@ Poco::Mutex Utility::_mutex; Utility::Utility() { - Poco::Mutex::ScopedLock l(_mutex); - if (_types.empty()) { _types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING)); @@ -135,7 +133,11 @@ MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size { poco_assert_dbg (pStmt); - static Utility u; + // Ensure statics are initialized + { + Poco::Mutex::ScopedLock lock(_mutex); + static Utility u; + } const char* pc = sqlite3_column_decltype(pStmt, (int) pos); std::string sqliteType = pc ? pc : ""; @@ -314,4 +316,10 @@ void* Utility::eventHookRegister(sqlite3* pDB, RollbackCallbackType callbackFn, } +// NOTE: Utility::dbHandle() has been moved to SessionImpl.cpp, +// as a workaround for a failing AnyCast with Clang. +// See +// for a discussion. + + } } } // namespace Poco::Data::SQLite