X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fpostgresqlstorage.cpp;h=0ae2d6d26162f56e32d826e12f4df2cab92fefcd;hp=1d2cd500cb5fad33e053b50df49e44625be8a660;hb=09515f0300f18490ee1788392a7518a6e1ab5acc;hpb=035cc9d5ce8fbcb4ab1740e682b19213ac2a625b diff --git a/src/core/postgresqlstorage.cpp b/src/core/postgresqlstorage.cpp index 1d2cd500..0ae2d6d2 100644 --- a/src/core/postgresqlstorage.cpp +++ b/src/core/postgresqlstorage.cpp @@ -48,6 +48,7 @@ AbstractSqlMigrationWriter *PostgreSqlStorage::createMigrationWriter() { } bool PostgreSqlStorage::isAvailable() const { + qDebug() << QSqlDatabase::drivers(); if(!QSqlDatabase::isDriverAvailable("QPSQL")) return false; return true; } @@ -79,12 +80,10 @@ QVariantMap PostgreSqlStorage::setupDefaults() const { return map; } -bool PostgreSqlStorage::setup(const QVariantMap &settings) { - bool success = AbstractSqlStorage::setup(settings); - if(success) { - logDb().exec(QString("ALTER USER %1 SET standard_conforming_strings TO on").arg(userName())); - } - return success; +void PostgreSqlStorage::initDbSession(QSqlDatabase &db) { + // this blows... but unfortunately Qt's PG driver forces us to this... + db.exec("set standard_conforming_strings = off"); + db.exec("set escape_string_warning = off"); } void PostgreSqlStorage::setConnectionProperties(const QVariantMap &properties) { @@ -151,12 +150,13 @@ UserId PostgreSqlStorage::addUser(const QString &user, const QString &password) return uid; } -void PostgreSqlStorage::updateUser(UserId user, const QString &password) { +bool PostgreSqlStorage::updateUser(UserId user, const QString &password) { QSqlQuery query(logDb()); query.prepare(queryString("update_userpassword")); query.bindValue(":userid", user.toInt()); query.bindValue(":password", cryptedPassword(password)); safeExec(query); + return query.numRowsAffected() != 0; } void PostgreSqlStorage::renameUser(UserId user, const QString &newName) { @@ -182,6 +182,19 @@ UserId PostgreSqlStorage::validateUser(const QString &user, const QString &passw } } +UserId PostgreSqlStorage::getUserId(const QString &user) { + QSqlQuery query(logDb()); + query.prepare(queryString("select_userid")); + query.bindValue(":username", user); + safeExec(query); + + if(query.first()) { + return query.value(0).toInt(); + } else { + return 0; + } +} + UserId PostgreSqlStorage::internalUser() { QSqlQuery query(logDb()); query.prepare(queryString("select_internaluser")); @@ -537,7 +550,7 @@ NetworkId PostgreSqlStorage::createNetwork(UserId user, const NetworkInfo &info) } if(!db.commit()) { - qWarning() << "PostgreSqlStorage::updateNetwork(): commiting data failed!"; + qWarning() << "PostgreSqlStorage::createNetwork(): commiting data failed!"; qWarning() << " -" << qPrintable(db.lastError().text()); return NetworkId(); } @@ -546,7 +559,7 @@ NetworkId PostgreSqlStorage::createNetwork(UserId user, const NetworkInfo &info) void PostgreSqlStorage::bindNetworkInfo(QSqlQuery &query, const NetworkInfo &info) { query.bindValue(":networkname", info.networkName); - query.bindValue(":identityid", info.identity.toInt()); + query.bindValue(":identityid", info.identity.isValid() ? info.identity.toInt() : QVariant()); query.bindValue(":encodingcodec", QString(info.codecForEncoding)); query.bindValue(":decodingcodec", QString(info.codecForDecoding)); query.bindValue(":servercodec", QString(info.codecForServer)); @@ -555,6 +568,9 @@ void PostgreSqlStorage::bindNetworkInfo(QSqlQuery &query, const NetworkInfo &inf query.bindValue(":useautoidentify", info.useAutoIdentify); query.bindValue(":autoidentifyservice", info.autoIdentifyService); query.bindValue(":autoidentifypassword", info.autoIdentifyPassword); + query.bindValue(":usesasl", info.useSasl); + query.bindValue(":saslaccount", info.saslAccount); + query.bindValue(":saslpassword", info.saslPassword); query.bindValue(":useautoreconnect", info.useAutoReconnect); query.bindValue(":autoreconnectinterval", info.autoReconnectInterval); query.bindValue(":autoreconnectretries", info.autoReconnectRetries); @@ -694,6 +710,9 @@ QList PostgreSqlStorage::networks(UserId user) { net.autoReconnectRetries = networksQuery.value(13).toInt(); net.unlimitedReconnectRetries = networksQuery.value(14).toBool(); net.rejoinChannels = networksQuery.value(15).toBool(); + net.useSasl = networksQuery.value(16).toBool(); + net.saslAccount = networksQuery.value(17).toString(); + net.saslPassword = networksQuery.value(18).toString(); serversQuery.bindValue(":networkid", net.networkId.toInt()); safeExec(serversQuery); @@ -894,6 +913,8 @@ BufferInfo PostgreSqlStorage::bufferInfo(UserId user, const NetworkId &networkId createQuery.bindValue(":buffertype", (int)type); createQuery.bindValue(":buffername", buffer); createQuery.bindValue(":buffercname", buffer.toLower()); + createQuery.bindValue(":joined", type & BufferInfo::ChannelBuffer ? true : false); + safeExec(createQuery); if(createQuery.lastError().isValid()) { @@ -1053,7 +1074,7 @@ bool PostgreSqlStorage::mergeBuffersPermanently(const UserId &user, const Buffer } QSqlQuery checkQuery(db); - checkQuery.prepare("SELECT count(*) FROM buffer" + checkQuery.prepare("SELECT count(*) FROM buffer " "WHERE userid = :userid AND bufferid IN (:buffer1, :buffer2)"); checkQuery.bindValue(":userid", user.toInt()); checkQuery.bindValue(":buffer1", bufferId1.toInt()); @@ -1130,6 +1151,44 @@ QHash PostgreSqlStorage::bufferLastSeenMsgIds(UserId user) { return lastSeenHash; } +void PostgreSqlStorage::setBufferMarkerLineMsg(UserId user, const BufferId &bufferId, const MsgId &msgId) { + QSqlQuery query(logDb()); + query.prepare(queryString("update_buffer_markerlinemsgid")); + + query.bindValue(":userid", user.toInt()); + query.bindValue(":bufferid", bufferId.toInt()); + query.bindValue(":markerlinemsgid", msgId.toInt()); + safeExec(query); + watchQuery(query); +} + +QHash PostgreSqlStorage::bufferMarkerLineMsgIds(UserId user) { + QHash markerLineHash; + + QSqlDatabase db = logDb(); + if(!beginReadOnlyTransaction(db)) { + qWarning() << "PostgreSqlStorage::bufferMarkerLineMsgIds(): cannot start read only transaction!"; + qWarning() << " -" << qPrintable(db.lastError().text()); + return markerLineHash; + } + + QSqlQuery query(db); + query.prepare(queryString("select_buffer_markerlinemsgids")); + query.bindValue(":userid", user.toInt()); + safeExec(query); + if(!watchQuery(query)) { + db.rollback(); + return markerLineHash; + } + + while(query.next()) { + markerLineHash[query.value(0).toInt()] = query.value(1).toInt(); + } + + db.commit(); + return markerLineHash; +} + bool PostgreSqlStorage::logMessage(Message &msg) { QSqlDatabase db = logDb(); if(!db.transaction()) { @@ -1601,6 +1660,9 @@ bool PostgreSqlMigrationWriter::writeMo(const NetworkMO &network) { bindValue(19, network.awaymessage); bindValue(20, network.attachperform); bindValue(21, network.detachperform); + bindValue(22, network.usesasl); + bindValue(23, network.saslaccount); + bindValue(24, network.saslpassword); return exec(); } @@ -1614,8 +1676,9 @@ bool PostgreSqlMigrationWriter::writeMo(const BufferMO &buffer) { bindValue(5, buffer.buffercname); bindValue(6, (int)buffer.buffertype); bindValue(7, buffer.lastseenmsgid); - bindValue(8, buffer.key); - bindValue(9, buffer.joined); + bindValue(8, buffer.markerlinemsgid); + bindValue(9, buffer.key); + bindValue(10, buffer.joined); return exec(); }