X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fsqlitestorage.cpp;h=e40150c49ac074ae7656f5aa28c46d1f7532bea9;hp=f38a948cc96c6132076bdcb861d389e2144bb8b6;hb=6a63070246d89aa2a2474e3a9a1035fa889ad77e;hpb=d09f943e9a6cb563b479bef5a4e909fbae6b768f diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index f38a948c..e40150c4 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -1756,8 +1756,18 @@ bool SqliteStorage::logMessage(Message &msg) { QSqlQuery logMessageQuery(db); logMessageQuery.prepare(queryString("insert_message")); - - logMessageQuery.bindValue(":time", msg.timestamp().toTime_t()); + // Store timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need to store a + // fractional number to support toMSecsSinceEpoch(), or an upgrade step would need to + // convert all past times to milliseconds, multiplying by 1000. +#if QT_VERSION >= 0x050800 + logMessageQuery.bindValue(":time", msg.timestamp().toSecsSinceEpoch()); +#else + // toSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#toMSecsSinceEpoch + logMessageQuery.bindValue(":time", (qint64)(msg.timestamp().toMSecsSinceEpoch() / 1000)); +#endif logMessageQuery.bindValue(":bufferid", msg.bufferInfo().bufferId().toInt()); logMessageQuery.bindValue(":type", msg.type()); logMessageQuery.bindValue(":flags", (int)msg.flags()); @@ -1839,8 +1849,19 @@ bool SqliteStorage::logMessages(MessageList &msgs) logMessageQuery.prepare(queryString("insert_message")); for (int i = 0; i < msgs.count(); i++) { Message &msg = msgs[i]; - - logMessageQuery.bindValue(":time", msg.timestamp().toTime_t()); + // Store timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need to store a + // fractional number to support toMSecsSinceEpoch(), or an upgrade step would need to + // convert all past times to milliseconds, multiplying by 1000. +#if QT_VERSION >= 0x050800 + logMessageQuery.bindValue(":time", msg.timestamp().toSecsSinceEpoch()); +#else + // toSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#toMSecsSinceEpoch + logMessageQuery.bindValue(":time", + (qint64)(msg.timestamp().toMSecsSinceEpoch() / 1000)); +#endif logMessageQuery.bindValue(":bufferid", msg.bufferInfo().bufferId().toInt()); logMessageQuery.bindValue(":type", msg.type()); logMessageQuery.bindValue(":flags", (int)msg.flags()); @@ -1929,7 +1950,20 @@ QList SqliteStorage::requestMsgs(UserId user, BufferId bufferId, MsgId watchQuery(query); while (query.next()) { - Message msg(QDateTime::fromTime_t(query.value(1).toInt()), + Message msg( + // Read timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need to store + // a fractional number to support fromMSecsSinceEpoch(), or an upgrade step would + // need to convert all past times to milliseconds, multiplying by 1000. +#if QT_VERSION >= 0x050800 + QDateTime::fromSecsSinceEpoch(query.value(1).toLongLong()), +#else + // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for + // now. + // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch + QDateTime::fromMSecsSinceEpoch((qint64)(query.value(1).toLongLong() * 1000)), +#endif bufferInfo, (Message::Type)query.value(2).toInt(), query.value(8).toString(), @@ -2005,7 +2039,22 @@ QList SqliteStorage::requestMsgsFiltered(UserId user, BufferId bufferId watchQuery(query); while (query.next()) { - Message msg(QDateTime::fromTime_t(query.value(1).toInt()), + Message msg( + // Read timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need + // to store a fractional number to support fromMSecsSinceEpoch(), or an + // upgrade step would need to convert all past times to milliseconds, + // multiplying by 1000. +#if QT_VERSION >= 0x050800 + QDateTime::fromSecsSinceEpoch(query.value(1).toLongLong()), +#else + // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to + // seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch + QDateTime::fromMSecsSinceEpoch( + (qint64)(query.value(1).toLongLong() * 1000)), +#endif bufferInfo, (Message::Type)query.value(2).toInt(), query.value(8).toString(), @@ -2062,7 +2111,20 @@ QList SqliteStorage::requestAllMsgs(UserId user, MsgId first, MsgId las watchQuery(query); while (query.next()) { - Message msg(QDateTime::fromTime_t(query.value(2).toInt()), + Message msg( + // Read timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need to store + // a fractional number to support fromMSecsSinceEpoch(), or an upgrade step would + // need to convert all past times to milliseconds, multiplying by 1000. +#if QT_VERSION >= 0x050800 + QDateTime::fromSecsSinceEpoch(query.value(2).toLongLong()), +#else + // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for + // now. + // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch + QDateTime::fromMSecsSinceEpoch((qint64)(query.value(2).toLongLong() * 1000)), +#endif bufferInfoHash[query.value(1).toInt()], (Message::Type)query.value(3).toInt(), query.value(9).toString(), @@ -2121,7 +2183,22 @@ QList SqliteStorage::requestAllMsgsFiltered(UserId user, MsgId first, M watchQuery(query); while (query.next()) { - Message msg(QDateTime::fromTime_t(query.value(2).toInt()), + Message msg( + // Read timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need + // to store a fractional number to support fromMSecsSinceEpoch(), or an + // upgrade step would need to convert all past times to milliseconds, + // multiplying by 1000. +#if QT_VERSION >= 0x050800 + QDateTime::fromSecsSinceEpoch(query.value(2).toLongLong()), +#else + // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to + // seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch + QDateTime::fromMSecsSinceEpoch( + (qint64)(query.value(2).toLongLong() * 1000)), +#endif bufferInfoHash[query.value(1).toInt()], (Message::Type)query.value(3).toInt(), query.value(9).toString(), @@ -2442,7 +2519,20 @@ bool SqliteMigrationReader::readMo(BacklogMO &backlog) } backlog.messageid = value(0).toLongLong(); - backlog.time = QDateTime::fromTime_t(value(1).toInt()).toUTC(); + // Read timestamp in seconds as 64-bit integer + // + // NOTE: This is a loss of precision. The database time column would need to store a + // fractional number to support fromMSecsSinceEpoch(), or an upgrade step would need to convert + // all past times to milliseconds, multiplying by 1000. +#if QT_VERSION >= 0x050800 + backlog.time = QDateTime::fromSecsSinceEpoch(value(1).toLongLong()).toUTC(); +#else + // fromSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for + // now. + // See https://doc.qt.io/qt-5/qdatetime.html#fromMSecsSinceEpoch + backlog.time = QDateTime::fromMSecsSinceEpoch((qint64)(value(1).toLongLong() * 1000) + ).toUTC(); +#endif backlog.bufferid = value(2).toInt(); backlog.type = value(3).toInt(); backlog.flags = value(4).toInt();