File indexing completed on 2025-01-05 04:46:57
0001 /* 0002 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "dbconfig.h" 0010 #include <QObject> 0011 #include <QProcess> 0012 0013 class QSqlDatabase; 0014 0015 namespace Akonadi 0016 { 0017 namespace Server 0018 { 0019 class DbConfigMysql : public QObject, public DbConfig 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 /** 0025 * Constructs a new DbConfig for MySQL reading configuration from the standard akonadiserverrc config file. 0026 */ 0027 explicit DbConfigMysql() = default; 0028 /** 0029 * Constructs a new DbConfig for MySQL reading configuration from the @p configFile. 0030 */ 0031 explicit DbConfigMysql(const QString &configFile); 0032 0033 /** 0034 * Destructor. 0035 */ 0036 ~DbConfigMysql() override; 0037 0038 /** 0039 * Returns the name of the used driver. 0040 */ 0041 QString driverName() const override; 0042 0043 /** 0044 * Returns the database name. 0045 */ 0046 QString databaseName() const override; 0047 0048 /** 0049 * Returns path to the database file or directory. 0050 */ 0051 QString databasePath() const override; 0052 0053 /** 0054 * Sets path to the database file or directory. 0055 */ 0056 void setDatabasePath(const QString &path, QSettings &settings) override; 0057 0058 /** 0059 * This method is called whenever the Akonadi server is started 0060 * and before the initial database connection is set up. 0061 * 0062 * At this point the default settings should be determined, merged 0063 * with the given @p settings and written back if @p storeSettings is true. 0064 */ 0065 bool init(QSettings &settings, bool storeSettings = true, const QString &dbPathOveride = {}) override; 0066 0067 /** 0068 * This method checks if the requirements for this database connection are met 0069 * in the system (QMYSQL driver is available, mysqld binary is found, etc.). 0070 */ 0071 bool isAvailable(QSettings &settings) override; 0072 0073 /** 0074 * This method applies the configured settings to the QtSql @p database 0075 * instance. 0076 */ 0077 void apply(QSqlDatabase &database) override; 0078 0079 /** 0080 * Returns whether an internal server needs to be used. 0081 */ 0082 bool useInternalServer() const override; 0083 0084 /** 0085 * This method is called to start an external server. 0086 */ 0087 bool startInternalServer() override; 0088 0089 /** 0090 * This method is called to stop the external server. 0091 */ 0092 void stopInternalServer() override; 0093 0094 /// reimpl 0095 void initSession(const QSqlDatabase &database) override; 0096 0097 /// reimpl 0098 bool disableConstraintChecks(const QSqlDatabase &db) override; 0099 0100 /// reimpl 0101 bool enableConstraintChecks(const QSqlDatabase &db) override; 0102 0103 private Q_SLOTS: 0104 void processFinished(int exitCode, QProcess::ExitStatus exitStatus); 0105 0106 private: 0107 int parseCommandLineToolsVersion() const; 0108 0109 bool initializeMariaDBDatabase(const QString &confFile, const QString &dataDir) const; 0110 bool initializeMySQL5_7_6Database(const QString &confFile, const QString &dataDir) const; 0111 bool initializeMySQLDatabase(const QString &confFile, const QString &dataDir) const; 0112 0113 QString mDatabaseName; 0114 QString mHostName; 0115 QString mUserName; 0116 QString mPassword; 0117 QString mConnectionOptions; 0118 QString mDataDir; 0119 QString mMysqldPath; 0120 QString mCleanServerShutdownCommand; 0121 QString mMysqlInstallDbPath; 0122 QString mMysqlCheckPath; 0123 QString mMysqlUpgradePath; 0124 bool mInternalServer = true; 0125 std::unique_ptr<QProcess> mDatabaseProcess; 0126 }; 0127 0128 } // namespace Server 0129 } // namespace Akonadi