Permalink
Browse files

Merge remote branch 'upstream/develop' into develop

  • Loading branch information...
2 parents 7ff7b75 + 3223166 commit d4c5db250c857b29f695f6bfeeb3f116c17bbe08 @pprindeville committed Dec 24, 2012
View
@@ -29,6 +29,11 @@ Release 1.5.0 (2012-12-17)
- fixed GH #30: Poco::Path::home() throws when called from Windows Service
- fixed GH #22: MySQL connection string lowercased
- added MySQL support for Date/Time
+- upgraded SQLite to version 3.7.15.1 (2012-12-19)
+- fixed SQLite affectedRows reporting and added tests
+- added SQLite::Utility::isThreadSafe() function
+- added SQLite::Utility::setThreadMode(int mode) function
+- fixed GH #41: Buffer::resize crash
Release 1.5.0 (2012-10-14)
==========================
@@ -80,4 +80,16 @@
#endif
#endif
+
+//
+// Thread safety mode defaults to "serialized".
+// See http://www.sqlite.org/threadsafe.html for details.
+// Threading mode significantly affects performance
+// (see TestSuite::benchmarkThreadModesTiming)
+//
+#ifndef SQLITE_THREADSAFE
+ #define SQLITE_THREADSAFE 1
+#endif
+
+
#endif // SQLite_SQLite_INCLUDED
@@ -63,6 +63,10 @@ class SQLite_API Utility
static const std::string SQLITE_TIME_FORMAT;
typedef std::map<std::string, MetaColumn::ColumnDataType> TypeMap;
+ static const int THREAD_MODE_SINGLE;
+ static const int THREAD_MODE_MULTI;
+ static const int THREAD_MODE_SERIAL;
+
Utility();
/// Maps SQLite column declared types to Poco::Data types through
/// static TypeMap member.
@@ -92,9 +96,25 @@ class SQLite_API Utility
///
/// Returns true if succesful
+ static bool isThreadSafe();
+ /// Returns true if SQLite was compiled in multi-thread or serialized mode.
+ /// See http://www.sqlite.org/c3ref/threadsafe.html for details.
+ ///
+ /// Returns true if succesful
+
+ static bool setThreadMode(int mode);
+ /// Sets the threading mode to single, multi or serialized.
+ /// See http://www.sqlite.org/threadsafe.html for details.
+ ///
+ /// Returns true if succesful
+
+ static int getThreadMode();
+ /// Returns the thread mode.
+
private:
static TypeMap _types;
Poco::FastMutex _mutex;
+ static int _threadMode;
};
@@ -88,7 +88,6 @@ void SQLiteStatementImpl::compileImpl()
if (SQLITE_OK != sqlite3_exec(_pDB, "delete from sys.dual where 1 <> 1;", 0, 0, 0))
throw ExecutionException("Error updating system database.");
}
-
_bindBegin = bindings().begin();
}
@@ -215,14 +214,15 @@ void SQLiteStatementImpl::bindImpl()
else if (bindCount > remainingBindCount)
throw ParameterCountMismatchException();
+ std::size_t boundRowCount;
if (_bindBegin != bindings().end())
{
- _affectedRowCount = (*_bindBegin)->numOfRowsHandled();
+ boundRowCount = (*_bindBegin)->numOfRowsHandled();
Bindings::iterator oldBegin = _bindBegin;
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
{
- if (_affectedRowCount != (*_bindBegin)->numOfRowsHandled())
+ if (boundRowCount != (*_bindBegin)->numOfRowsHandled())
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
(*_bindBegin)->bind(pos);
@@ -270,6 +270,9 @@ bool SQLiteStatementImpl::hasNext()
_stepCalled = true;
_nextResponse = sqlite3_step(_pStmt);
+ if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0;
+ _affectedRowCount += sqlite3_changes(_pDB);
+
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
Utility::throwException(_nextResponse);
@@ -296,15 +299,16 @@ std::size_t SQLiteStatementImpl::next()
_isExtracted = true;
}
_stepCalled = false;
+ if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0;
+ _affectedRowCount += (*extracts.begin())->numOfRowsHandled();
}
else if (SQLITE_DONE == _nextResponse)
{
throw Poco::Data::DataException("No data received");
}
else
{
- int rc = _nextResponse;
- Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
+ Utility::throwException(_nextResponse, std::string("Iterator Error: trying to access the next value"));
}
return 1u;
@@ -53,6 +53,18 @@ namespace Data {
namespace SQLite {
+const int Utility::THREAD_MODE_SINGLE = SQLITE_CONFIG_SINGLETHREAD;
+const int Utility::THREAD_MODE_MULTI = SQLITE_CONFIG_MULTITHREAD;
+const int Utility::THREAD_MODE_SERIAL = SQLITE_CONFIG_SERIALIZED;
+int Utility::_threadMode =
+#if (SQLITE_THREADSAFE == 0)
+ SQLITE_CONFIG_SINGLETHREAD;
+#elif (SQLITE_THREADSAFE == 1)
+ SQLITE_CONFIG_SERIALIZED;
+#elif (SQLITE_THREADSAFE == 2)
+ SQLITE_CONFIG_MULTITHREAD;
+#endif
+
const std::string Utility::SQLITE_DATE_FORMAT = "%Y-%m-%d";
const std::string Utility::SQLITE_TIME_FORMAT = "%H:%M:%S";
Utility::TypeMap Utility::_types;
@@ -255,4 +267,36 @@ bool Utility::memoryToFile(const std::string& fileName, sqlite3* pInMemory)
}
+bool Utility::isThreadSafe()
+{
+ return 0 != sqlite3_threadsafe();
+}
+
+
+int Utility::getThreadMode()
+{
+ return _threadMode;
+}
+
+
+bool Utility::setThreadMode(int mode)
+{
+#if (SQLITE_THREADSAFE != 0)
+ if (SQLITE_OK == sqlite3_shutdown())
+ {
+ if (SQLITE_OK == sqlite3_config(mode))
+ {
+ _threadMode = mode;
+ if (SQLITE_OK == sqlite3_initialize())
+ return true;
+ }
+ sqlite3_initialize();
+ }
+ return false;
+#else
+ return false;
+#endif
+}
+
+
} } } // namespace Poco::Data::SQLite
Oops, something went wrong.

0 comments on commit d4c5db2

Please sign in to comment.