File indexing completed on 2024-04-28 15:58:50

0001 /* This file is part of the KDE project
0002    Copyright (C) 2002 Lucijan Busch <lucijan@gmx.at>
0003    Copyright (C) 2003 Joseph Wenninger<jowenn@kde.org>
0004    Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This program is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this program; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KDB_MYSQLCONNECTION_H
0023 #define KDB_MYSQLCONNECTION_H
0024 
0025 #include <QStringList>
0026 
0027 #include "KDbConnection.h"
0028 
0029 class MysqlConnectionInternal;
0030 
0031 /*! @short Provides database connection, allowing queries and data modification.
0032 */
0033 class MysqlConnection : public KDbConnection
0034 {
0035     Q_DECLARE_TR_FUNCTIONS(MysqlConnection)
0036 public:
0037     ~MysqlConnection() override;
0038 
0039     Q_REQUIRED_RESULT KDbCursor *prepareQuery(const KDbEscapedString &sql,
0040                                               KDbCursor::Options options
0041                                               = KDbCursor::Option::None) override;
0042     Q_REQUIRED_RESULT KDbCursor *prepareQuery(KDbQuerySchema *query,
0043                                               KDbCursor::Options options
0044                                               = KDbCursor::Option::None) override;
0045 
0046     Q_REQUIRED_RESULT KDbPreparedStatementInterface *prepareStatementInternal() override;
0047 
0048 protected:
0049     /*! Used by driver */
0050     MysqlConnection(KDbDriver *driver, const KDbConnectionData& connData,
0051                     const KDbConnectionOptions &options);
0052 
0053     bool drv_connect() override;
0054     bool drv_getServerVersion(KDbServerVersionInfo* version) override;
0055     bool drv_disconnect() override;
0056     bool drv_getDatabasesList(QStringList* list) override;
0057     //! reimplemented using "SHOW DATABASES LIKE..." because MySQL stores db names in lower case.
0058     bool drv_databaseExists(const QString &dbName, bool ignoreErrors = true) override;
0059     bool drv_createDatabase(const QString &dbName = QString()) override;
0060     bool drv_useDatabase(const QString &dbName = QString(), bool *cancelled = nullptr,
0061                                  KDbMessageHandler* msgHandler = nullptr) override;
0062     bool drv_closeDatabase() override;
0063     bool drv_dropDatabase(const QString &dbName = QString()) override;
0064     Q_REQUIRED_RESULT KDbSqlResult *drv_prepareSql(const KDbEscapedString &sql) override;
0065     bool drv_executeSql(const KDbEscapedString& sql) override;
0066 
0067     //! Implemented for KDbResultable
0068     QString serverResultName() const override;
0069 
0070 //! @todo move this somewhere to low level class (MIGRATION?)
0071     tristate drv_containsTable(const QString &tableName) override;
0072 
0073     void storeResult();
0074 
0075     MysqlConnectionInternal* const d;
0076 
0077     friend class MysqlDriver;
0078     friend class MysqlCursorData;
0079     friend class MysqlSqlResult;
0080 private:
0081     Q_DISABLE_COPY(MysqlConnection)
0082 };
0083 
0084 #endif