{
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());
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());
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).toUInt(),
+ (Message::Type)query.value(2).toInt(),
query.value(8).toString(),
query.value(4).toString(),
query.value(5).toString(),
query.value(6).toString(),
query.value(7).toString(),
- (Message::Flags)query.value(3).toUInt());
+ (Message::Flags)query.value(3).toInt());
msg.setMsgId(query.value(0).toLongLong());
messagelist << msg;
}
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).toUInt(),
+ (Message::Type)query.value(2).toInt(),
query.value(8).toString(),
query.value(4).toString(),
query.value(5).toString(),
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).toUInt(),
+ (Message::Type)query.value(3).toInt(),
query.value(9).toString(),
query.value(5).toString(),
query.value(6).toString(),
query.value(7).toString(),
query.value(8).toString(),
- (Message::Flags)query.value(4).toUInt());
+ (Message::Flags)query.value(4).toInt());
msg.setMsgId(query.value(0).toLongLong());
messagelist << msg;
}
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).toUInt(),
+ (Message::Type)query.value(3).toInt(),
query.value(9).toString(),
query.value(5).toString(),
query.value(6).toString(),
bool SqliteMigrationReader::readMo(BacklogMO &backlog)
{
- int skipSteps = 0;
+ qint64 skipSteps = 0;
while (!next()) {
if (backlog.messageid < _maxId) {
bindValue(0, backlog.messageid.toQint64() + (skipSteps * stepSize()));
}
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();