#include <QtSql>
-#include "logger.h"
+#include "logmessage.h"
#include "network.h"
#include "quassel.h"
{
QSqlQuery logMessageQuery(db);
logMessageQuery.prepare(queryString("insert_message"));
-
- logMessageQuery.bindValue(":time", msg.timestamp().toTime_t());
+ // As of SQLite schema version 31, timestamps are stored in milliseconds instead of
+ // seconds. This nets us more precision as well as simplifying 64-bit time.
+ logMessageQuery.bindValue(":time", msg.timestamp().toMSecsSinceEpoch());
logMessageQuery.bindValue(":bufferid", msg.bufferInfo().bufferId().toInt());
logMessageQuery.bindValue(":type", msg.type());
logMessageQuery.bindValue(":flags", (int)msg.flags());
logMessageQuery.prepare(queryString("insert_message"));
for (int i = 0; i < msgs.count(); i++) {
Message &msg = msgs[i];
-
- logMessageQuery.bindValue(":time", msg.timestamp().toTime_t());
+ // As of SQLite schema version 31, timestamps are stored in milliseconds instead of
+ // seconds. This nets us more precision as well as simplifying 64-bit time.
+ logMessageQuery.bindValue(":time", msg.timestamp().toMSecsSinceEpoch());
logMessageQuery.bindValue(":bufferid", msg.bufferInfo().bufferId().toInt());
logMessageQuery.bindValue(":type", msg.type());
logMessageQuery.bindValue(":flags", (int)msg.flags());
watchQuery(query);
while (query.next()) {
- Message msg(QDateTime::fromTime_t(query.value(1).toInt()),
+ Message msg(
+ // As of SQLite schema version 31, timestamps are stored in milliseconds instead of
+ // seconds. This nets us more precision as well as simplifying 64-bit time.
+ QDateTime::fromMSecsSinceEpoch(query.value(1).toLongLong()),
bufferInfo,
(Message::Type)query.value(2).toInt(),
query.value(8).toString(),
watchQuery(query);
while (query.next()) {
- Message msg(QDateTime::fromTime_t(query.value(1).toInt()),
+ Message msg(
+ // As of SQLite schema version 31, timestamps are stored in milliseconds
+ // instead of seconds. This nets us more precision as well as simplifying
+ // 64-bit time.
+ QDateTime::fromMSecsSinceEpoch(query.value(1).toLongLong()),
bufferInfo,
(Message::Type)query.value(2).toInt(),
query.value(8).toString(),
watchQuery(query);
while (query.next()) {
- Message msg(QDateTime::fromTime_t(query.value(2).toInt()),
+ Message msg(
+ // As of SQLite schema version 31, timestamps are stored in milliseconds instead of
+ // seconds. This nets us more precision as well as simplifying 64-bit time.
+ QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong()),
bufferInfoHash[query.value(1).toInt()],
(Message::Type)query.value(3).toInt(),
query.value(9).toString(),
watchQuery(query);
while (query.next()) {
- Message msg(QDateTime::fromTime_t(query.value(2).toInt()),
+ Message msg(
+ // As of SQLite schema version 31, timestamps are stored in milliseconds
+ // instead of seconds. This nets us more precision as well as simplifying
+ // 64-bit time.
+ QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong()),
bufferInfoHash[query.value(1).toInt()],
(Message::Type)query.value(3).toInt(),
query.value(9).toString(),
}
-QString SqliteStorage::getAuthUserName(UserId user) {
- QString authusername;
- QSqlQuery query(logDb());
- query.prepare(queryString("select_authusername"));
- query.bindValue(":userid", user.toInt());
-
- lockForRead();
- safeExec(query);
- watchQuery(query);
- unlock();
-
- if (query.first()) {
- authusername = query.value(0).toString();
- }
-
- return authusername;
-}
-
-
QString SqliteStorage::backlogFile()
{
return Quassel::configDirPath() + "quassel-storage.sqlite";
switch (query.lastError().number()) {
case 5: // SQLITE_BUSY 5 /* The database file is locked */
- [[clang::fallthrough]];
+ // fallthrough
case 6: // SQLITE_LOCKED 6 /* A table in the database is locked */
if (retryCount < _maxRetryCount)
return safeExec(query, retryCount + 1);
}
backlog.messageid = value(0).toLongLong();
- backlog.time = QDateTime::fromTime_t(value(1).toInt()).toUTC();
+ // As of SQLite schema version 31, timestamps are stored in milliseconds instead of
+ // seconds. This nets us more precision as well as simplifying 64-bit time.
+ backlog.time = QDateTime::fromMSecsSinceEpoch(value(1).toLongLong()).toUTC();
backlog.bufferid = value(2).toInt();
backlog.type = value(3).toInt();
backlog.flags = value(4).toInt();