diff options
| author | Anton <anton@picapica> | 2017-12-01 22:16:24 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2017-12-01 22:16:24 +0400 |
| commit | 0f726c30f5f11990d325bc5e55015c42c80cd9d2 (patch) | |
| tree | f8c9b83cc440dd3a2f43285dc35199435f6e2701 /pica-client/history.cpp | |
| parent | ac041927bc0c82e33acaa9e15fd46ecca0b77172 (diff) | |
| download | pica-pica-0f726c30f5f11990d325bc5e55015c42c80cd9d2.tar.gz pica-pica-0f726c30f5f11990d325bc5e55015c42c80cd9d2.zip | |
fixed code style on all source files (*.c *.cpp *.h) using astyle --style=allman --lineend=linux --indent=tab --pad-oper
Diffstat (limited to 'pica-client/history.cpp')
| -rw-r--r-- | pica-client/history.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/pica-client/history.cpp b/pica-client/history.cpp index b3883dd..933e2a9 100644 --- a/pica-client/history.cpp +++ b/pica-client/history.cpp @@ -2,138 +2,138 @@ #include <QDebug> History::History(QString storage, QByteArray my_id) - : me_(my_id) + : me_(my_id) { - dbconn=QSqlDatabase::addDatabase("QSQLITE"); - dbconn.setDatabaseName(storage); + dbconn = QSqlDatabase::addDatabase("QSQLITE"); + dbconn.setDatabaseName(storage); - if (!dbconn.open()) - { - lasterr=dbconn.lastError(); - return; - } + if (!dbconn.open()) + { + lasterr = dbconn.lastError(); + return; + } - QSqlQuery query; + QSqlQuery query; - query.exec("PRAGMA foreign_keys=ON;"); + query.exec("PRAGMA foreign_keys=ON;"); - //check result, if foreign keys support is on + //check result, if foreign keys support is on } void History::Add(QByteArray peer_id, QString message, bool is_me) { - QSqlQuery query; + QSqlQuery query; - query.prepare( - "insert into \"history\" (\"contact_id\", \"account_id\", \"is_me\", \"is_delivered\", \"message\", \"id\", \"timestamp\") \ + query.prepare( + "insert into \"history\" (\"contact_id\", \"account_id\", \"is_me\", \"is_delivered\", \"message\", \"id\", \"timestamp\") \ values (:contact_id, :account_id, :is_me, :is_delivered, :message, null, strftime('%s','now'));" - ); + ); - query.bindValue(":contact_id", peer_id); - query.bindValue(":account_id", me_); + query.bindValue(":contact_id", peer_id); + query.bindValue(":account_id", me_); - if (is_me) - { - query.bindValue(":is_me", 1); - query.bindValue(":is_delivered", 0); - } - else - { - query.bindValue(":is_me", 0); - query.bindValue(":is_delivered", 1); - } + if (is_me) + { + query.bindValue(":is_me", 1); + query.bindValue(":is_delivered", 0); + } + else + { + query.bindValue(":is_me", 0); + query.bindValue(":is_delivered", 1); + } - query.bindValue(":message", message); + query.bindValue(":message", message); - query.exec(); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); } void History::SetDelivered(QByteArray peer_id) { - QSqlQuery query; + QSqlQuery query; - query.prepare("update history set is_delivered=1 where id in \ + query.prepare("update history set is_delivered=1 where id in \ (select id from history where \ is_delivered=0 and is_me=1 and contact_id=:peer_id and account_id=:me order by id asc limit 1)" - ); + ); - query.bindValue(":peer_id", peer_id); - query.bindValue(":me", me_); + query.bindValue(":peer_id", peer_id); + query.bindValue(":me", me_); - query.exec(); - lasterr=query.lastError(); + query.exec(); + lasterr = query.lastError(); } QList<History::HistoryRecord> History::GetMessages(QByteArray peer_id, quint32 start_timestamp, quint32 end_timestamp) { - QList<HistoryRecord> L; - HistoryRecord r; - QSqlQuery query; + QList<HistoryRecord> L; + HistoryRecord r; + QSqlQuery query; - query.setForwardOnly(true); - query.prepare("select contact_id, is_me, is_delivered, timestamp, message from history \ + query.setForwardOnly(true); + query.prepare("select contact_id, is_me, is_delivered, timestamp, message from history \ where contact_id=:peer_id and account_id=:me and timestamp >= :start and timestamp <=:end order by id" - ); + ); - query.bindValue(":peer_id", peer_id); - query.bindValue(":me", me_); - query.bindValue(":start", start_timestamp); - query.bindValue(":end", end_timestamp); - query.exec(); + query.bindValue(":peer_id", peer_id); + query.bindValue(":me", me_); + query.bindValue(":start", start_timestamp); + query.bindValue(":end", end_timestamp); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); - if (lasterr.isValid()) - return L; + if (lasterr.isValid()) + return L; - while(query.next()) - { - r.peer_id = query.value(0).toByteArray(); - r.is_me = query.value(1).toBool(); - r.is_delivered = query.value(2).toBool(); - r.timestamp = query.value(3).toUInt(); - r.message = query.value(4).toString(); + while(query.next()) + { + r.peer_id = query.value(0).toByteArray(); + r.is_me = query.value(1).toBool(); + r.is_delivered = query.value(2).toBool(); + r.timestamp = query.value(3).toUInt(); + r.message = query.value(4).toString(); - L<<r; - } + L << r; + } - return L; + return L; } QMap<QByteArray, QList<QString> > History::GetUndeliveredMessages() { - QMap<QByteArray, QList<QString> > M; - QSqlQuery query; + QMap<QByteArray, QList<QString> > M; + QSqlQuery query; - query.setForwardOnly(true); - query.prepare("select contact_id, message from history \ + query.setForwardOnly(true); + query.prepare("select contact_id, message from history \ where account_id=:me and is_delivered=0 and is_me=1 order by id" - ); + ); - query.bindValue(":me", me_); - query.exec(); + query.bindValue(":me", me_); + query.exec(); - lasterr=query.lastError(); + lasterr = query.lastError(); - if (lasterr.isValid()) - return M; + if (lasterr.isValid()) + return M; - while(query.next()) - { - M[query.value(0).toByteArray()] << query.value(1).toString(); - } + while(query.next()) + { + M[query.value(0).toByteArray()] << query.value(1).toString(); + } - return M; + return M; } bool History::isOK() { - return !lasterr.isValid(); + return !lasterr.isValid(); } QString History::GetLastError() { - return lasterr.text(); + return lasterr.text(); } |
