kexi

keximigrate.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
00003    Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
00004    Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
00005 
00006    This program is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this program; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KEXI_MIGRATE_H
00023 #define KEXI_MIGRATE_H
00024 
00025 
00026 #include "kexidb/tableschema.h"
00027 #include "kexidb/connection.h"
00028 #include "keximigratedata.h"
00029 
00030 #include <kgenericfactory.h>
00031 #include <qstringlist.h>
00032 #include <qguardedptr.h>
00033 
00034 class KexiProject;
00035 namespace Kexi
00036 {
00037     class ObjectStatus;
00038 }
00039 
00047 #define KEXI_MIGRATION_VERSION_MAJOR 1
00048 #define KEXI_MIGRATION_VERSION_MINOR 1
00049 
00054 namespace KexiMigration 
00055 {
00056 
00058 KEXIMIGR_EXPORT int versionMajor();
00059 
00061 KEXIMIGR_EXPORT int versionMinor();
00062 
00063 
00065 
00078 class KEXIMIGR_EXPORT KexiMigrate : public QObject, public KexiDB::Object
00079 {
00080     Q_OBJECT
00081 
00082     public:
00083         virtual ~KexiMigrate();
00084 
00086         KexiMigration::Data* data() const { return m_migrateData; }
00087 
00090         void setData(KexiMigration::Data* migrateData);
00091 
00101         bool checkIfDestinationDatabaseOverwritingNeedsAccepting(Kexi::ObjectStatus* result,
00102             bool& acceptingNeeded);
00103 
00106         bool isSourceAndDestinationDataSourceTheSame() const;
00107 
00109         bool performImport(Kexi::ObjectStatus* result = 0);
00110 
00112         bool performExport(Kexi::ObjectStatus* result = 0);
00113 
00115         inline bool progressSupported() { return drv_progressSupported(); }
00116 
00117         virtual int versionMajor() const = 0;
00118         virtual int versionMinor() const = 0;
00119 
00123         virtual QVariant propertyValue( const QCString& propName );
00124 
00126         void setPropertyValue( const QCString& propName, const QVariant& value );
00127 
00131         QString propertyCaption( const QCString& propName ) const;
00132 
00135         QValueList<QCString> propertyNames() const;
00136 
00140         virtual bool isValid();
00141 
00142     signals:
00143         void progressPercent(int percent);
00144 
00145     protected:
00147         KexiMigrate(QObject *parent, const char *name, const QStringList &args = QStringList());
00148 
00150         virtual bool drv_connect() = 0;
00152         virtual bool drv_disconnect() = 0;
00153 
00155         virtual bool drv_tableNames(QStringList& tablenames) = 0;
00156 
00158         virtual bool drv_readTableSchema(
00159             const QString& originalName, KexiDB::TableSchema& tableSchema) = 0;
00160 
00170         virtual bool drv_queryMaxNumber(const QString& tableName, 
00171             const QString& columnName, int& result);
00172 
00180 
00181         virtual tristate drv_queryStringListFromSQL(
00182             const QString& sqlStatement, uint columnNumber, QStringList& stringList, int numRecords = -1)
00183          { return cancelled; }
00184 
00190 
00191         virtual tristate drv_querySingleStringFromSQL(const QString& sqlStatement, 
00192             uint columnNumber, QString& string);
00193 
00201 
00202         virtual tristate drv_fetchRecordFromSQL(const QString& sqlStatement, 
00203             KexiDB::RowData& data, bool &firstRecord)
00204          { return cancelled; }
00205 
00209         virtual bool drv_copyTable(const QString& srcTable, KexiDB::Connection *destConn, 
00210             KexiDB::TableSchema* dstTable) = 0;
00211 
00212         virtual bool drv_progressSupported() { return false; }
00213 
00231         virtual bool drv_getTableSize(const QString&, Q_ULLONG&)
00232         { return false; }
00233 
00234         void updateProgress(Q_ULLONG step = 1ULL);
00235 
00238         KexiDB::Field::Type userType(const QString& fname);
00239 
00240         virtual QString drv_escapeIdentifier( const QString& str ) const {
00241             return m_kexiDBDriver ? m_kexiDBDriver->escapeIdentifier(str) : str; }
00242 
00245         KexiMigration::Data* m_migrateData;
00246 
00247 //          // Temporary values used during import (set by driver specific methods)
00248 //          KexiDB::Field* m_f;
00249 
00253         QMap<QCString,QVariant> m_properties;
00254 
00258         QMap<QCString,QString> m_propertyCaptions;
00259 
00261         QGuardedPtr<KexiDB::Driver> m_kexiDBDriver;
00262 
00263     private:
00265         bool tableNames(QStringList& tablenames);
00266 
00268         QPtrList<KexiDB::TableSchema> m_tableSchemas;
00269 
00270         QPtrList<KexiDB::TableSchema> m_kexiDBCompatibleTableSchemasToRemoveFromMemoryAfterImport;
00271 
00276         bool progressInitialise();
00277 
00278         KexiProject *m_destPrj;
00279 
00281         Q_ULLONG m_progressTotal;
00282 
00284         Q_ULLONG m_progressDone;
00285 
00287         Q_ULLONG m_progressNextReport;
00288 
00289         friend class MigrateManager;
00290 };
00291 
00292 } //namespace KexiMigration
00293 
00296 #define KEXIMIGRATE_DRIVER_INFO( class_name, internal_name ) \
00297     int class_name::versionMajor() const { return KEXI_MIGRATION_VERSION_MAJOR; } \
00298     int class_name::versionMinor() const { return KEXI_MIGRATION_VERSION_MINOR; } \
00299     K_EXPORT_COMPONENT_FACTORY(keximigrate_ ## internal_name, \
00300       KGenericFactory<KexiMigration::class_name>( "keximigrate_" #internal_name ))
00301 
00304 #define KEXIMIGRATION_DRIVER \
00305     public: \
00306     virtual int versionMajor() const; \
00307     virtual int versionMinor() const;
00308 
00309 #endif
00310 
KDE Home | KDE Accessibility Home | Description of Access Keys