File indexing completed on 2024-05-12 16:40:15
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Martin Ellis <m.a.ellis@ncl.ac.uk> 0003 Copyright (C) 2006-2016 Jarosław Staniek <staniek@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this program; see the file COPYING. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KEXISQLMIGRATE_H 0022 #define KEXISQLMIGRATE_H 0023 0024 #include <keximigrate.h> 0025 0026 //! @short A specialized class for a migrate plugin that imports native SQL databases into Kexi projects 0027 //! Compared to more generic KexiMigrate, KexiSqlMigrate implements needed methods using 0028 //! low level APIs of KDb. This is used for example by MySQL and PostgreSQL migration plugins. 0029 class KEXIMIGRATE_EXPORT KexiSqlMigrate : public KexiMigration::KexiMigrate 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 //! Constructs a migrate plugin that uses low level APIs of KDb driver @a kdbDriverId. 0035 //! @a kdbDriverId must not be empty. 0036 explicit KexiSqlMigrate(const QString &kdbDriverId, QObject *parent, 0037 const QVariantList& args = QVariantList()); 0038 0039 virtual ~KexiSqlMigrate(); 0040 0041 protected: 0042 //! Driver specific function to return table names 0043 bool drv_tableNames(QStringList *tablenames) override; 0044 0045 //! Driver specific implementation to read a table schema 0046 bool drv_readTableSchema( 0047 const QString& originalName, KDbTableSchema *tableSchema) override; 0048 0049 //! Driver specific connection creation 0050 KDbConnection* drv_createConnection() override; 0051 0052 /*! Fetches single string at column \a columnNumber for each record from result obtained 0053 by running \a sqlStatement. \a numRecords can be specified to limit number of records read. 0054 If \a numRecords is -1, all records are loaded. 0055 @see KexiMigrate::drv_queryStringListFromSql() */ 0056 tristate drv_queryStringListFromSql( 0057 const KDbEscapedString& sqlStatement, int columnNumber, 0058 QStringList *stringList, int numRecords = -1) override; 0059 0060 //! Copy a table from source DB to target DB (driver specific) 0061 bool drv_copyTable(const QString& srcTable, 0062 KDbConnection *destConn, KDbTableSchema* dstTable, 0063 const RecordFilter *recordFilter = nullptr) override; 0064 0065 bool drv_progressSupported() override { 0066 return true; 0067 } 0068 0069 bool drv_getTableSize(const QString& table, quint64* size) override; 0070 0071 //! @todo move this somewhere to low level class (MIGRATION?) virtual bool drv_getTablesList( QStringList &list ); 0072 //! @todo move this somewhere to low level class (MIGRATION?) virtual bool drv_containsTable( const QString &tableName ); 0073 0074 //Extended API 0075 //! Starts reading data from the source dataset's table 0076 QSharedPointer<KDbSqlResult> drv_readFromTable(const QString & tableName) override; 0077 0078 const QString m_kdbDriverId; 0079 }; 0080 0081 #endif