X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fpostgresqlstorage.cpp;h=6b2642bdb7c489db0ce05c33b2398fad9fd9a450;hp=5bad7588197f2c19189827de35871396766c5ba8;hb=158443f71d48215eea8b47b836b61afd77654b78;hpb=79aa3994d78860c0b7a623a46ce44dffff988fd9 diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index 5bad7588..6b2642bd 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -22,13 +22,12 @@ #include -#include "logger.h" +#include "logmessage.h" #include "network.h" #include "quassel.h" PostgreSqlStorage::PostgreSqlStorage(QObject *parent) - : AbstractSqlStorage(parent), - _port(-1) + : AbstractSqlStorage(parent) { } @@ -1371,7 +1370,7 @@ void PostgreSqlStorage::setBufferLastSeenMsg(UserId user, const BufferId &buffer query.bindValue(":userid", user.toInt()); query.bindValue(":bufferid", bufferId.toInt()); - query.bindValue(":lastseenmsgid", msgId.toInt()); + query.bindValue(":lastseenmsgid", msgId.toQint64()); safeExec(query); watchQuery(query); } @@ -1398,7 +1397,7 @@ QHash PostgreSqlStorage::bufferLastSeenMsgIds(UserId user) } while (query.next()) { - lastSeenHash[query.value(0).toInt()] = query.value(1).toInt(); + lastSeenHash[query.value(0).toInt()] = query.value(1).toLongLong(); } db.commit(); @@ -1413,7 +1412,7 @@ void PostgreSqlStorage::setBufferMarkerLineMsg(UserId user, const BufferId &buff query.bindValue(":userid", user.toInt()); query.bindValue(":bufferid", bufferId.toInt()); - query.bindValue(":markerlinemsgid", msgId.toInt()); + query.bindValue(":markerlinemsgid", msgId.toQint64()); safeExec(query); watchQuery(query); } @@ -1440,7 +1439,7 @@ QHash PostgreSqlStorage::bufferMarkerLineMsgIds(UserId user) } while (query.next()) { - markerLineHash[query.value(0).toInt()] = query.value(1).toInt(); + markerLineHash[query.value(0).toInt()] = query.value(1).toLongLong(); } db.commit(); @@ -1493,10 +1492,10 @@ Message::Types PostgreSqlStorage::bufferActivity(BufferId bufferId, MsgId lastSe QSqlQuery query(logDb()); query.prepare(queryString("select_buffer_bufferactivity")); query.bindValue(":bufferid", bufferId.toInt()); - query.bindValue(":lastseenmsgid", lastSeenMsgId.toInt()); + query.bindValue(":lastseenmsgid", lastSeenMsgId.toQint64()); safeExec(query); watchQuery(query); - Message::Types result = Message::Types(0); + Message::Types result = Message::Types(nullptr); if (query.first()) result = Message::Types(query.value(0).toInt()); return result; @@ -1586,7 +1585,7 @@ int PostgreSqlStorage::highlightCount(BufferId bufferId, MsgId lastSeenMsgId) QSqlQuery query(logDb()); query.prepare(queryString("select_buffer_highlightcount")); query.bindValue(":bufferid", bufferId.toInt()); - query.bindValue(":lastseenmsgid", lastSeenMsgId.toInt()); + query.bindValue(":lastseenmsgid", lastSeenMsgId.toQint64()); safeExec(query); watchQuery(query); int result = int(0); @@ -1609,9 +1608,9 @@ bool PostgreSqlStorage::logMessage(Message &msg) << msg.realName() << msg.avatarUrl(); QSqlQuery getSenderIdQuery = executePreparedQuery("select_senderid", senderParams, db); - int senderId; + qint64 senderId; if (getSenderIdQuery.first()) { - senderId = getSenderIdQuery.value(0).toInt(); + senderId = getSenderIdQuery.value(0).toLongLong(); } else { // it's possible that the sender was already added by another thread @@ -1624,16 +1623,18 @@ bool PostgreSqlStorage::logMessage(Message &msg) getSenderIdQuery = executePreparedQuery("select_senderid", senderParams, db); watchQuery(getSenderIdQuery); getSenderIdQuery.first(); - senderId = getSenderIdQuery.value(0).toInt(); + senderId = getSenderIdQuery.value(0).toLongLong(); } else { releaseSavePoint("sender_sp1", db); addSenderQuery.first(); - senderId = addSenderQuery.value(0).toInt(); + senderId = addSenderQuery.value(0).toLongLong(); } } QVariantList params; + // PostgreSQL handles QDateTime()'s serialized format by default, and QDateTime() serializes + // to a 64-bit time compatible format by default. params << msg.timestamp() << msg.bufferInfo().bufferId().toInt() << msg.type() @@ -1649,7 +1650,7 @@ bool PostgreSqlStorage::logMessage(Message &msg) } logMessageQuery.first(); - MsgId msgId = logMessageQuery.value(0).toInt(); + MsgId msgId = logMessageQuery.value(0).toLongLong(); db.commit(); if (msgId.isValid()) { msg.setMsgId(msgId); @@ -1671,7 +1672,7 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) } QList senderIdList; - QHash senderIds; + QHash senderIds; QSqlQuery addSenderQuery; QSqlQuery selectSenderQuery;; for (int i = 0; i < msgs.count(); i++) { @@ -1689,8 +1690,8 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) selectSenderQuery = executePreparedQuery("select_senderid", senderParams, db); if (selectSenderQuery.first()) { - senderIdList << selectSenderQuery.value(0).toInt(); - senderIds[sender] = selectSenderQuery.value(0).toInt(); + senderIdList << selectSenderQuery.value(0).toLongLong(); + senderIds[sender] = selectSenderQuery.value(0).toLongLong(); } else { savePoint("sender_sp", db); @@ -1701,14 +1702,14 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) selectSenderQuery = executePreparedQuery("select_senderid", senderParams, db); watchQuery(selectSenderQuery); selectSenderQuery.first(); - senderIdList << selectSenderQuery.value(0).toInt(); - senderIds[sender] = selectSenderQuery.value(0).toInt(); + senderIdList << selectSenderQuery.value(0).toLongLong(); + senderIds[sender] = selectSenderQuery.value(0).toLongLong(); } else { releaseSavePoint("sender_sp", db); addSenderQuery.first(); - senderIdList << addSenderQuery.value(0).toInt(); - senderIds[sender] = addSenderQuery.value(0).toInt(); + senderIdList << addSenderQuery.value(0).toLongLong(); + senderIds[sender] = addSenderQuery.value(0).toLongLong(); } } } @@ -1718,6 +1719,8 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) for (int i = 0; i < msgs.count(); i++) { Message &msg = msgs[i]; QVariantList params; + // PostgreSQL handles QDateTime()'s serialized format by default, and QDateTime() serializes + // to a 64-bit time compatible format by default. params << msg.timestamp() << msg.bufferInfo().bufferId().toInt() << msg.type() @@ -1733,7 +1736,7 @@ bool PostgreSqlStorage::logMessages(MessageList &msgs) } else { logMessageQuery.first(); - msg.setMsgId(logMessageQuery.value(0).toInt()); + msg.setMsgId(logMessageQuery.value(0).toLongLong()); } } @@ -1774,12 +1777,12 @@ QList PostgreSqlStorage::requestMsgs(UserId user, BufferId bufferId, Ms } else if (last == -1) { queryName = "select_messagesNewerThan"; - params << first.toInt(); + params << first.toQint64(); } else { queryName = "select_messagesRange"; - params << first.toInt(); - params << last.toInt(); + params << first.toQint64(); + params << last.toQint64(); } params << bufferId.toInt(); if (limit != -1) @@ -1797,18 +1800,20 @@ QList PostgreSqlStorage::requestMsgs(UserId user, BufferId bufferId, Ms QDateTime timestamp; while (query.next()) { + // PostgreSQL returns date/time in ISO 8601 format, no 64-bit handling needed + // See https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT timestamp = query.value(1).toDateTime(); timestamp.setTimeSpec(Qt::UTC); Message msg(timestamp, 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()); - msg.setMsgId(query.value(0).toInt()); + (Message::Flags)query.value(3).toInt()); + msg.setMsgId(query.value(0).toLongLong()); messagelist << msg; } @@ -1839,11 +1844,11 @@ QList PostgreSqlStorage::requestMsgsFiltered(UserId user, BufferId buff query.prepare(queryString("select_messagesNewestK_filtered")); } else if (last == -1) { query.prepare(queryString("select_messagesNewerThan_filtered")); - query.bindValue(":first", first.toInt()); + query.bindValue(":first", first.toQint64()); } else { query.prepare(queryString("select_messagesRange_filtered")); - query.bindValue(":last", last.toInt()); - query.bindValue(":first", first.toInt()); + query.bindValue(":last", last.toQint64()); + query.bindValue(":first", first.toQint64()); } query.bindValue(":buffer", bufferId.toInt()); query.bindValue(":limit", limit); @@ -1861,18 +1866,20 @@ QList PostgreSqlStorage::requestMsgsFiltered(UserId user, BufferId buff QDateTime timestamp; while (query.next()) { + // PostgreSQL returns date/time in ISO 8601 format, no 64-bit handling needed + // See https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT timestamp = query.value(1).toDateTime(); timestamp.setTimeSpec(Qt::UTC); Message msg(timestamp, 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).toInt()}); - msg.setMsgId(query.value(0).toInt()); + msg.setMsgId(query.value(0).toLongLong()); messagelist << msg; } @@ -1904,10 +1911,10 @@ QList PostgreSqlStorage::requestAllMsgs(UserId user, MsgId first, MsgId } else { query.prepare(queryString("select_messagesAll")); - query.bindValue(":lastmsg", last.toInt()); + query.bindValue(":lastmsg", last.toQint64()); } query.bindValue(":userid", user.toInt()); - query.bindValue(":firstmsg", first.toInt()); + query.bindValue(":firstmsg", first.toQint64()); safeExec(query); if (!watchQuery(query)) { db.rollback(); @@ -1916,18 +1923,20 @@ QList PostgreSqlStorage::requestAllMsgs(UserId user, MsgId first, MsgId QDateTime timestamp; for (int i = 0; i < limit && query.next(); i++) { + // PostgreSQL returns date/time in ISO 8601 format, no 64-bit handling needed + // See https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT timestamp = query.value(2).toDateTime(); timestamp.setTimeSpec(Qt::UTC); Message msg(timestamp, 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()); - msg.setMsgId(query.value(0).toInt()); + (Message::Flags)query.value(4).toInt()); + msg.setMsgId(query.value(0).toLongLong()); messagelist << msg; } @@ -1959,10 +1968,10 @@ QList PostgreSqlStorage::requestAllMsgsFiltered(UserId user, MsgId firs } else { query.prepare(queryString("select_messagesAll_filtered")); - query.bindValue(":lastmsg", last.toInt()); + query.bindValue(":lastmsg", last.toQint64()); } query.bindValue(":userid", user.toInt()); - query.bindValue(":firstmsg", first.toInt()); + query.bindValue(":firstmsg", first.toQint64()); int typeRaw = type; query.bindValue(":type", typeRaw); @@ -1978,18 +1987,20 @@ QList PostgreSqlStorage::requestAllMsgsFiltered(UserId user, MsgId firs QDateTime timestamp; for (int i = 0; i < limit && query.next(); i++) { + // PostgreSQL returns date/time in ISO 8601 format, no 64-bit handling needed + // See https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT timestamp = query.value(2).toDateTime(); timestamp.setTimeSpec(Qt::UTC); Message msg(timestamp, 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).toInt()}); - msg.setMsgId(query.value(0).toInt()); + msg.setMsgId(query.value(0).toLongLong()); messagelist << msg; } @@ -2012,21 +2023,6 @@ QMap PostgreSqlStorage::getAllAuthUserNames() } -QString PostgreSqlStorage::getAuthUserName(UserId user) -{ - QString authusername; - QSqlQuery query(logDb()); - query.prepare(queryString("select_authusername")); - query.bindValue(":userid", user.toInt()); - safeExec(query); - watchQuery(query); - - if (query.first()) { - authusername = query.value(0).toString(); - } - return authusername; -} - // void PostgreSqlStorage::safeExec(QSqlQuery &query) { // qDebug() << "PostgreSqlStorage::safeExec"; // qDebug() << " executing:\n" << query.executedQuery(); @@ -2288,7 +2284,7 @@ bool PostgreSqlMigrationWriter::writeMo(const IdentityMO &identity) bindValue(11, identity.autoAwayReasonEnabled); bindValue(12, identity.detachAwayEnabled); bindValue(13, identity.detachAwayReason); - bindValue(14, identity.detchAwayReasonEnabled); + bindValue(14, identity.detachAwayReasonEnabled); bindValue(15, identity.ident); bindValue(16, identity.kickReason); bindValue(17, identity.partReason); @@ -2374,7 +2370,7 @@ bool PostgreSqlMigrationWriter::writeMo(const BufferMO &buffer) //bool PostgreSqlMigrationWriter::writeBacklog(const BacklogMO &backlog) { bool PostgreSqlMigrationWriter::writeMo(const BacklogMO &backlog) { - bindValue(0, backlog.messageid.toInt()); + bindValue(0, backlog.messageid.toQint64()); bindValue(1, backlog.time); bindValue(2, backlog.bufferid.toInt()); bindValue(3, backlog.type);