diff options
Diffstat (limited to 'Swiften/History/SQLiteHistoryStorage.cpp')
-rw-r--r-- | Swiften/History/SQLiteHistoryStorage.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Swiften/History/SQLiteHistoryStorage.cpp b/Swiften/History/SQLiteHistoryStorage.cpp index 5e3148b..ed0d6a3 100644 --- a/Swiften/History/SQLiteHistoryStorage.cpp +++ b/Swiften/History/SQLiteHistoryStorage.cpp @@ -8,6 +8,7 @@ #include <boost/lexical_cast.hpp> #include <sqlite3.h> +#include <3rdParty/SQLite/sqlite3async.h> #include <Swiften/History/SQLiteHistoryStorage.h> #include <boost/date_time/gregorian/gregorian.hpp> @@ -25,7 +26,14 @@ inline std::string getEscapedString(const std::string& s) { namespace Swift { SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) { - sqlite3_open(file.c_str(), &db_); + sqlite3_vfs vfs; + + sqlite3async_initialize(NULL, true); + sqlite3_vfs_register(&vfs, false); + + thread_ = new boost::thread(boost::bind(&SQLiteHistoryStorage::run, this)); + + sqlite3_open_v2(file.c_str(), &db_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "sqlite3async"); if (!db_) { std::cerr << "Error opening database " << file << std::endl; } @@ -45,7 +53,9 @@ SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) { } SQLiteHistoryStorage::~SQLiteHistoryStorage() { + sqlite3async_shutdown(); sqlite3_close(db_); + delete thread_; } void SQLiteHistoryStorage::addMessage(const HistoryMessage& message) { @@ -371,4 +381,8 @@ boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID return boost::posix_time::ptime(boost::posix_time::not_a_date_time); } +void SQLiteHistoryStorage::run() { + sqlite3async_run(); +} + } |