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, 
00183             int numRecords = -1)
00184          { Q_UNUSED(sqlStatement); Q_UNUSED(columnNumber); Q_UNUSED(stringList);
00185            Q_UNUSED(numRecords); 
00186            return cancelled; }
00187 
00193 
00194         virtual tristate drv_querySingleStringFromSQL(const QString& sqlStatement, 
00195             uint columnNumber, QString& string);
00196 
00204 
00205         virtual tristate drv_fetchRecordFromSQL(const QString& sqlStatement, 
00206             KexiDB::RowData& data, bool &firstRecord)
00207          { Q_UNUSED(sqlStatement); Q_UNUSED(data); Q_UNUSED(firstRecord);
00208            return cancelled; }
00209 
00213         virtual bool drv_copyTable(const QString& srcTable, KexiDB::Connection *destConn, 
00214             KexiDB::TableSchema* dstTable) = 0;
00215 
00216         virtual bool drv_progressSupported() { return false; }
00217 
00235         virtual bool drv_getTableSize(const QString&, Q_ULLONG&)
00236         { return false; }
00237 
00238         void updateProgress(Q_ULLONG step = 1ULL);
00239 
00242         KexiDB::Field::Type userType(const QString& fname);
00243 
00244         virtual QString drv_escapeIdentifier( const QString& str ) const {
00245             return m_kexiDBDriver ? m_kexiDBDriver->escapeIdentifier(str) : str; }
00246 
00249         KexiMigration::Data* m_migrateData;
00250 
00251 //          // Temporary values used during import (set by driver specific methods)
00252 //          KexiDB::Field* m_f;
00253 
00257         QMap<QCString,QVariant> m_properties;
00258 
00262         QMap<QCString,QString> m_propertyCaptions;
00263 
00265         QGuardedPtr<KexiDB::Driver> m_kexiDBDriver;
00266 
00267     private:
00269         bool tableNames(QStringList& tablenames);
00270 
00272         QPtrList<KexiDB::TableSchema> m_tableSchemas;
00273 
00274         QPtrList<KexiDB::TableSchema> m_kexiDBCompatibleTableSchemasToRemoveFromMemoryAfterImport;
00275 
00280         bool progressInitialise();
00281 
00282         KexiProject *m_destPrj;
00283 
00285         Q_ULLONG m_progressTotal;
00286 
00288         Q_ULLONG m_progressDone;
00289 
00291         Q_ULLONG m_progressNextReport;
00292 
00293         friend class MigrateManager;
00294 };
00295 
00296 } //namespace KexiMigration
00297 
00300 #define KEXIMIGRATE_DRIVER_INFO( class_name, internal_name ) \
00301     int class_name::versionMajor() const { return KEXI_MIGRATION_VERSION_MAJOR; } \
00302     int class_name::versionMinor() const { return KEXI_MIGRATION_VERSION_MINOR; } \
00303     K_EXPORT_COMPONENT_FACTORY(keximigrate_ ## internal_name, \
00304       KGenericFactory<KexiMigration::class_name>( "keximigrate_" #internal_name ))
00305 
00308 #define KEXIMIGRATION_DRIVER \
00309     public: \
00310     virtual int versionMajor() const; \
00311     virtual int versionMinor() const;
00312 
00313 #endif
00314 
KDE Home | KDE Accessibility Home | Description of Access Keys