summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/History')
-rw-r--r--Swiften/History/HistoryStorage.h2
-rw-r--r--Swiften/History/SConscript1
-rw-r--r--Swiften/History/SQLiteHistoryStorage.cpp55
-rw-r--r--Swiften/History/SQLiteHistoryStorage.h16
4 files changed, 36 insertions, 38 deletions
diff --git a/Swiften/History/HistoryStorage.h b/Swiften/History/HistoryStorage.h
index fcf28b5..6d24d15 100644
--- a/Swiften/History/HistoryStorage.h
+++ b/Swiften/History/HistoryStorage.h
@@ -21,7 +21,7 @@ namespace Swift {
* Messages are stored using localtime timestamps.
*/
public:
- virtual ~HistoryStorage() {};
+ virtual ~HistoryStorage() {}
virtual void addMessage(const HistoryMessage& message) = 0;
virtual std::vector<HistoryMessage> getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const = 0;
diff --git a/Swiften/History/SConscript b/Swiften/History/SConscript
index 44b3cc4..ac3cf3b 100644
--- a/Swiften/History/SConscript
+++ b/Swiften/History/SConscript
@@ -3,7 +3,6 @@ Import("swiften_env")
myenv = swiften_env.Clone()
if myenv["target"] == "native":
myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS", {}))
- myenv.MergeFlags(swiften_env.get("SQLITE_FLAGS_ASYNC", {}))
if myenv["experimental"]:
objects = myenv.SwiftenObject([
diff --git a/Swiften/History/SQLiteHistoryStorage.cpp b/Swiften/History/SQLiteHistoryStorage.cpp
index 04bd00f..dda8766 100644
--- a/Swiften/History/SQLiteHistoryStorage.cpp
+++ b/Swiften/History/SQLiteHistoryStorage.cpp
@@ -1,16 +1,17 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <iostream>
#include <boost/lexical_cast.hpp>
+#include <boost/numeric/conversion/cast.hpp>
#include <sqlite3.h>
-#include <3rdParty/SQLiteAsync/sqlite3async.h>
#include <Swiften/History/SQLiteHistoryStorage.h>
#include <boost/date_time/gregorian/gregorian.hpp>
+#include <Swiften/Base/Path.h>
inline std::string getEscapedString(const std::string& s) {
std::string result(s);
@@ -25,14 +26,12 @@ inline std::string getEscapedString(const std::string& s) {
namespace Swift {
-SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) {
- sqlite3async_initialize(NULL, false);
-
+SQLiteHistoryStorage::SQLiteHistoryStorage(const boost::filesystem::path& file) : db_(0) {
thread_ = new boost::thread(boost::bind(&SQLiteHistoryStorage::run, this));
- sqlite3_open_v2(file.c_str(), &db_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "sqlite3async");
+ sqlite3_open(pathToString(file).c_str(), &db_);
if (!db_) {
- std::cerr << "Error opening database " << file << std::endl;
+ std::cerr << "Error opening database " << pathToString(file) << std::endl;
}
char* errorMessage;
@@ -50,7 +49,6 @@ SQLiteHistoryStorage::SQLiteHistoryStorage(const std::string& file) : db_(0) {
}
SQLiteHistoryStorage::~SQLiteHistoryStorage() {
- sqlite3async_shutdown();
sqlite3_close(db_);
delete thread_;
}
@@ -78,8 +76,8 @@ void SQLiteHistoryStorage::addMessage(const HistoryMessage& message) {
std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromDate(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date) const {
sqlite3_stmt* selectStatement;
- boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
- boost::optional<int> contactID = getIDFromJID(contactJID.toBare());
+ boost::optional<long long> selfID = getIDFromJID(selfJID.toBare());
+ boost::optional<long long> contactID = getIDFromJID(contactJID.toBare());
if (!selfID || !contactID) {
// JIDs missing from the database
@@ -111,7 +109,7 @@ std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromDate(const JID&
" AND time<" + boost::lexical_cast<std::string>(upperBound) + ")";
}
- int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
+ int r = sqlite3_prepare(db_, selectQuery.c_str(), boost::numeric_cast<int>(selectQuery.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
@@ -157,8 +155,8 @@ std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromDate(const JID&
return result;
}
-int SQLiteHistoryStorage::getIDForJID(const JID& jid) {
- boost::optional<int> id = getIDFromJID(jid);
+long long SQLiteHistoryStorage::getIDForJID(const JID& jid) {
+ boost::optional<long long> id = getIDFromJID(jid);
if (id) {
return *id;
}
@@ -167,7 +165,7 @@ int SQLiteHistoryStorage::getIDForJID(const JID& jid) {
}
}
-int SQLiteHistoryStorage::addJID(const JID& jid) {
+long long SQLiteHistoryStorage::addJID(const JID& jid) {
std::string statement = std::string("INSERT INTO jids('jid') VALUES('") + getEscapedString(jid.toString()) + "')";
char* errorMessage;
int result = sqlite3_exec(db_, statement.c_str(), 0, 0, &errorMessage);
@@ -178,11 +176,11 @@ int SQLiteHistoryStorage::addJID(const JID& jid) {
return sqlite3_last_insert_rowid(db_);
}
-boost::optional<JID> SQLiteHistoryStorage::getJIDFromID(int id) const {
+boost::optional<JID> SQLiteHistoryStorage::getJIDFromID(long long id) const {
boost::optional<JID> result;
sqlite3_stmt* selectStatement;
std::string selectQuery("SELECT jid FROM jids WHERE id=" + boost::lexical_cast<std::string>(id));
- int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
+ int r = sqlite3_prepare(db_, selectQuery.c_str(), boost::numeric_cast<int>(selectQuery.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
@@ -194,17 +192,17 @@ boost::optional<JID> SQLiteHistoryStorage::getJIDFromID(int id) const {
return result;
}
-boost::optional<int> SQLiteHistoryStorage::getIDFromJID(const JID& jid) const {
- boost::optional<int> result;
+boost::optional<long long> SQLiteHistoryStorage::getIDFromJID(const JID& jid) const {
+ boost::optional<long long> result;
sqlite3_stmt* selectStatement;
std::string selectQuery("SELECT id FROM jids WHERE jid='" + jid.toString() + "'");
- int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
+ long long r = sqlite3_prepare(db_, selectQuery.c_str(), boost::numeric_cast<int>(selectQuery.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
r = sqlite3_step(selectStatement);
if (r == SQLITE_ROW) {
- result = boost::optional<int>(sqlite3_column_int(selectStatement, 0));
+ result = boost::optional<long long>(sqlite3_column_int(selectStatement, 0));
}
sqlite3_finalize(selectStatement);
return result;
@@ -215,7 +213,7 @@ ContactsMap SQLiteHistoryStorage::getContacts(const JID& selfJID, HistoryMessage
sqlite3_stmt* selectStatement;
// get id
- boost::optional<int> id = getIDFromJID(selfJID);
+ boost::optional<long long> id = getIDFromJID(selfJID);
if (!id) {
return result;
}
@@ -231,7 +229,7 @@ ContactsMap SQLiteHistoryStorage::getContacts(const JID& selfJID, HistoryMessage
query += " AND message LIKE '%" + getEscapedString(keyword) + "%'";
}
- int r = sqlite3_prepare(db_, query.c_str(), query.size(), &selectStatement, NULL);
+ int r = sqlite3_prepare(db_, query.c_str(), boost::numeric_cast<int>(query.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
@@ -280,8 +278,8 @@ ContactsMap SQLiteHistoryStorage::getContacts(const JID& selfJID, HistoryMessage
boost::gregorian::date SQLiteHistoryStorage::getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const {
sqlite3_stmt* selectStatement;
- boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
- boost::optional<int> contactID = getIDFromJID(contactJID.toBare());
+ boost::optional<long long> selfID = getIDFromJID(selfJID.toBare());
+ boost::optional<long long> contactID = getIDFromJID(contactJID.toBare());
if (!selfID || !contactID) {
// JIDs missing from the database
@@ -310,7 +308,7 @@ boost::gregorian::date SQLiteHistoryStorage::getNextDateWithLogs(const JID& self
selectQuery += " AND time" + (reverseOrder ? std::string("<") : std::string(">")) + boost::lexical_cast<std::string>(timeStamp);
selectQuery += " ORDER BY time " + (reverseOrder ? std::string("DESC") : std::string("ASC")) + " LIMIT 1";
- int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
+ int r = sqlite3_prepare(db_, selectQuery.c_str(), boost::numeric_cast<int>(selectQuery.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
@@ -347,8 +345,8 @@ std::vector<HistoryMessage> SQLiteHistoryStorage::getMessagesFromPreviousDate(co
}
boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID& selfJID, const JID& mucJID) const {
- boost::optional<int> selfID = getIDFromJID(selfJID.toBare());
- boost::optional<int> mucID = getIDFromJID(mucJID.toBare());
+ boost::optional<long long> selfID = getIDFromJID(selfJID.toBare());
+ boost::optional<long long> mucID = getIDFromJID(mucJID.toBare());
if (!selfID || !mucID) {
// JIDs missing from the database
@@ -361,7 +359,7 @@ boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID
boost::lexical_cast<std::string>(*selfID) + " AND fromBare=" +
boost::lexical_cast<std::string>(*mucID) + ") ORDER BY time DESC LIMIT 1";
- int r = sqlite3_prepare(db_, selectQuery.c_str(), selectQuery.size(), &selectStatement, NULL);
+ int r = sqlite3_prepare(db_, selectQuery.c_str(), boost::numeric_cast<int>(selectQuery.size()), &selectStatement, NULL);
if (r != SQLITE_OK) {
std::cout << "Error: " << sqlite3_errmsg(db_) << std::endl;
}
@@ -379,7 +377,6 @@ boost::posix_time::ptime SQLiteHistoryStorage::getLastTimeStampFromMUC(const JID
}
void SQLiteHistoryStorage::run() {
- sqlite3async_run();
}
}
diff --git a/Swiften/History/SQLiteHistoryStorage.h b/Swiften/History/SQLiteHistoryStorage.h
index 782334a..2c1ba7a 100644
--- a/Swiften/History/SQLiteHistoryStorage.h
+++ b/Swiften/History/SQLiteHistoryStorage.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -8,15 +8,17 @@
#include <boost/optional.hpp>
+#include <Swiften/Base/API.h>
#include <Swiften/History/HistoryStorage.h>
#include <boost/thread.hpp>
+#include <boost/filesystem/path.hpp>
struct sqlite3;
namespace Swift {
- class SQLiteHistoryStorage : public HistoryStorage {
+ class SWIFTEN_API SQLiteHistoryStorage : public HistoryStorage {
public:
- SQLiteHistoryStorage(const std::string& file);
+ SQLiteHistoryStorage(const boost::filesystem::path& file);
~SQLiteHistoryStorage();
void addMessage(const HistoryMessage& message);
@@ -29,11 +31,11 @@ namespace Swift {
private:
void run();
boost::gregorian::date getNextDateWithLogs(const JID& selfJID, const JID& contactJID, HistoryMessage::Type type, const boost::gregorian::date& date, bool reverseOrder) const;
- int getIDForJID(const JID&);
- int addJID(const JID&);
+ long long getIDForJID(const JID&);
+ long long addJID(const JID&);
- boost::optional<JID> getJIDFromID(int id) const;
- boost::optional<int> getIDFromJID(const JID& jid) const;
+ boost::optional<JID> getJIDFromID(long long id) const;
+ boost::optional<long long> getIDFromJID(const JID& jid) const;
sqlite3* db_;
boost::thread* thread_;