/***************************************************************************
- * Copyright (C) 2005-2015 by the Quassel Project *
+ * Copyright (C) 2005-2019 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#ifndef ABSTRACTSQLSTORAGE_H
-#define ABSTRACTSQLSTORAGE_H
+#pragma once
#include "storage.h"
+#include <memory>
+
+#include <QList>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
AbstractSqlStorage(QObject *parent = 0);
virtual ~AbstractSqlStorage();
- virtual inline AbstractSqlMigrationReader *createMigrationReader() { return 0; }
- virtual inline AbstractSqlMigrationWriter *createMigrationWriter() { return 0; }
+ virtual std::unique_ptr<AbstractSqlMigrationReader> createMigrationReader() { return {}; }
+ virtual std::unique_ptr<AbstractSqlMigrationWriter> createMigrationWriter() { return {}; }
+
+ /**
+ * An SQL query with associated resource filename
+ */
+ struct SqlQueryResource {
+ QString queryString; ///< SQL query string
+ QString queryFilename; ///< Path to the resource file providing this query
+
+ SqlQueryResource(const QString& queryString, const QString& queryFilename)
+ : queryString(std::move(queryString)),
+ queryFilename(std::move(queryFilename)) {}
+ };
public slots:
- virtual State init(const QVariantMap &settings = QVariantMap());
- virtual bool setup(const QVariantMap &settings = QVariantMap());
+ virtual State init(const QVariantMap &settings = QVariantMap(),
+ const QProcessEnvironment &environment = {},
+ bool loadFromEnvironment = false);
+ virtual bool setup(const QVariantMap &settings = QVariantMap(),
+ const QProcessEnvironment &environment = {},
+ bool loadFromEnvironment = false);
protected:
inline virtual void sync() {};
QSqlDatabase logDb();
- QString queryString(const QString &queryName, int version);
- inline QString queryString(const QString &queryName) { return queryString(queryName, 0); }
+ /**
+ * Fetch an SQL query string by name and optional schema version
+ *
+ * Loads the named SQL query from the built-in SQL resource collection, returning it as a
+ * string. If a version is specified, it'll be loaded from the schema version-specific folder
+ * instead.
+ *
+ * @see schemaVersion()
+ *
+ * @param[in] queryName File name of the SQL query, minus the .sql extension
+ * @param[in] version
+ * @parblock
+ * SQL schema version; if 0, fetches from current version, otherwise loads from the specified
+ * schema version instead of the current schema files.
+ * @endparblock
+ * @return String with the requested SQL query, ready for parameter substitution
+ */
+ QString queryString(const QString &queryName, int version = 0);
- QStringList setupQueries();
+ /**
+ * Gets the collection of SQL setup queries and filenames to create a new database
+ *
+ * @return List of SQL query strings and filenames
+ */
+ QList<SqlQueryResource> setupQueries();
- QStringList upgradeQueries(int ver);
+ /**
+ * Gets the collection of SQL upgrade queries and filenames for a given schema version
+ *
+ * @param ver SQL schema version
+ * @return List of SQL query strings and filenames
+ */
+ QList<SqlQueryResource> upgradeQueries(int ver);
bool upgradeDb();
bool watchQuery(QSqlQuery &query);
int schemaVersion();
virtual int installedSchemaVersion() { return -1; };
- virtual bool updateSchemaVersion(int newVersion) = 0;
+
+ /**
+ * Update the stored schema version number, optionally clearing the record of mid-schema steps
+ *
+ * @param newVersion New schema version number
+ * @param clearUpgradeStep If true, clear the record of any in-progress schema upgrades
+ * @return
+ */
+ virtual bool updateSchemaVersion(int newVersion, bool clearUpgradeStep = true) = 0;
+
virtual bool setupSchemaVersion(int version) = 0;
- virtual void setConnectionProperties(const QVariantMap &properties) = 0;
+ /**
+ * Gets the last successful schema upgrade step, or an empty string if no upgrade is in progress
+ *
+ * @return Filename of last successful schema upgrade query, or empty string if not upgrading
+ */
+ virtual QString schemaVersionUpgradeStep();
+
+ /**
+ * Sets the last successful schema upgrade step
+ *
+ * @param upgradeQuery The filename of the last successful schema upgrade query
+ * @return True if successfully set, otherwise false
+ */
+ virtual bool setSchemaVersionUpgradeStep(QString upgradeQuery) = 0;
+ virtual void setConnectionProperties(const QVariantMap &properties,
+ const QProcessEnvironment &environment,
+ bool loadFromEnvironment) = 0;
virtual QString driverName() = 0;
inline virtual QString hostName() { return QString(); }
inline virtual int port() { return -1; }
QHash<QThread *, Connection *> _connectionPool;
};
+struct SenderData {
+ QString sender;
+ QString realname;
+ QString avatarurl;
+
+ friend uint qHash(const SenderData &key);
+ friend bool operator==(const SenderData &a, const SenderData &b);
+};
// ========================================
// AbstractSqlStorage::Connection
QString username;
QString password;
int hashversion;
+ QString authenticator;
};
struct SenderMO {
- int senderId;
+ qint64 senderId;
QString sender;
+ QString realname;
+ QString avatarurl;
SenderMO() : senderId(0) {}
};
bool autoAwayReasonEnabled;
bool detachAwayEnabled;
QString detachAwayReason;
- bool detchAwayReasonEnabled;
+ bool detachAwayReasonEnabled;
QString ident;
QString kickReason;
QString partReason;
};
struct NetworkMO {
- NetworkId networkid;
UserId userid;
QString networkname;
- IdentityId identityid;
- QString encodingcodec;
- QString decodingcodec;
- QString servercodec;
- bool userandomserver;
QString perform;
- bool useautoidentify;
QString autoidentifyservice;
QString autoidentifypassword;
- bool useautoreconnect;
- int autoreconnectinterval;
- int autoreconnectretries;
- bool unlimitedconnectretries;
- bool rejoinchannels;
- bool connected;
+ QString saslaccount;
+ QString saslpassword;
+ QString servercodec;
+ QString encodingcodec;
+ QString decodingcodec;
QString usermode;
QString awaymessage;
QString attachperform;
QString detachperform;
+ NetworkId networkid;
+ IdentityId identityid;
+ int messagerateburstsize;
+ int messageratedelay;
+ int autoreconnectinterval;
+ int autoreconnectretries;
+ bool rejoinchannels;
+ bool userandomserver;
+ bool useautoidentify;
bool usesasl;
- QString saslaccount;
- QString saslpassword;
+ bool useautoreconnect;
+ bool unlimitedconnectretries;
+ bool usecustommessagerate;
+ bool unlimitedmessagerate;
+ bool connected;
};
struct BufferMO {
QString buffername;
QString buffercname;
int buffertype;
- int lastseenmsgid;
- int markerlinemsgid;
+ qint64 lastmsgid;
+ qint64 lastseenmsgid;
+ qint64 markerlinemsgid;
+ int bufferactivity;
+ int highlightcount;
QString key;
bool joined;
+ QString cipher;
};
struct BacklogMO {
BufferId bufferid;
int type;
int flags;
- int senderid;
+ qint64 senderid;
+ QString senderprefixes;
QString message;
};
int port;
QString password;
bool ssl;
+ bool sslverify; /// If true, validate SSL certificates
int sslversion;
bool useproxy;
int proxytype;
QByteArray settingvalue;
};
+ struct CoreStateMO {
+ QString key;
+ QByteArray value;
+ };
+
enum MigrationObject {
QuasselUser,
Sender,
Buffer,
Backlog,
IrcServer,
- UserSetting
+ UserSetting,
+ CoreState
};
AbstractSqlMigrator();
virtual bool readMo(BacklogMO &backlog) = 0;
virtual bool readMo(IrcServerMO &ircserver) = 0;
virtual bool readMo(UserSettingMO &userSetting) = 0;
+ virtual bool readMo(CoreStateMO &coreState) = 0;
bool migrateTo(AbstractSqlMigrationWriter *writer);
virtual bool writeMo(const BacklogMO &backlog) = 0;
virtual bool writeMo(const IrcServerMO &ircserver) = 0;
virtual bool writeMo(const UserSettingMO &userSetting) = 0;
+ virtual bool writeMo(const CoreStateMO &coreState) = 0;
inline bool migrateFrom(AbstractSqlMigrationReader *reader) { return reader->migrateTo(this); }
virtual inline bool postProcess() { return true; }
friend class AbstractSqlMigrationReader;
};
-
-
-#endif