- virtual bool init(const QVariantMap &settings = QVariantMap());
- inline virtual void sync() {};
-
- QSqlDatabase logDb();
-
- QString queryString(const QString &queryName, int version);
- inline QString queryString(const QString &queryName) { return queryString(queryName, 0); }
-
- QStringList setupQueries();
- bool setup(const QVariantMap &settings = QVariantMap());
-
- QStringList upgradeQueries(int ver);
- bool upgradeDb();
-
- bool watchQuery(QSqlQuery &query);
-
- int schemaVersion();
- virtual int installedSchemaVersion() { return -1; };
-
- virtual QString driverName() = 0;
- inline virtual QString hostName() { return QString(); }
- virtual QString databaseName() = 0;
- inline virtual QString userName() { return QString(); }
- inline virtual QString password() { return QString(); }
+ inline void sync() override{};
+
+ QSqlDatabase logDb();
+
+ /**
+ * 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);
+
+ /**
+ * Gets the collection of SQL setup queries and filenames to create a new database
+ *
+ * @return List of SQL query strings and filenames
+ */
+ std::vector<SqlQueryResource> setupQueries();
+
+ /**
+ * 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
+ */
+ std::vector<SqlQueryResource> upgradeQueries(int ver);
+ bool upgradeDb();
+
+ bool watchQuery(QSqlQuery& query);
+
+ int schemaVersion();
+ virtual int installedSchemaVersion() { return -1; };
+
+ /**
+ * 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;
+
+ /**
+ * 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; }
+ virtual QString databaseName() = 0;
+ inline virtual QString userName() { return QString(); }
+ inline virtual QString password() { return QString(); }
+
+ //! Initialize db specific features on connect
+ /** This is called every time a connection to a specific SQL backend is established
+ * the default implementation does nothing.
+ *
+ * When reimplementing this method, don't use logDB() inside this function as
+ * this would cause as we're just about to initialize that DB connection.
+ */
+ inline virtual bool initDbSession(QSqlDatabase& /* db */) { return true; }