Fix genversion error in unclean build directories
[quassel.git] / src / core / postgresqlstorage.cpp
index d8a6284..0ae2d6d 100644 (file)
@@ -48,6 +48,7 @@ AbstractSqlMigrationWriter *PostgreSqlStorage::createMigrationWriter() {
 }
 
 bool PostgreSqlStorage::isAvailable() const {
+  qDebug() << QSqlDatabase::drivers();
   if(!QSqlDatabase::isDriverAvailable("QPSQL")) return false;
   return true;
 }
@@ -567,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);
@@ -706,6 +710,9 @@ QList<NetworkInfo> 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);
@@ -906,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()) {
@@ -1142,6 +1151,44 @@ QHash<BufferId, MsgId> 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<BufferId, MsgId> PostgreSqlStorage::bufferMarkerLineMsgIds(UserId user) {
+  QHash<BufferId, MsgId> 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()) {
@@ -1613,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();
 }
 
@@ -1626,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();
 }