kexi

keximigrate.h
1/* This file is part of the KDE project
2 Copyright (C) 2004 Adam Pigg <adam@piggz.co.uk>
3 Copyright (C) 2004-2006 Jaroslaw Staniek <js@iidea.pl>
4 Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KEXI_MIGRATE_H
23#define KEXI_MIGRATE_H
24
25
26#include "kexidb/tableschema.h"
27#include "kexidb/connection.h"
28#include "keximigratedata.h"
29
30#include <kgenericfactory.h>
31#include <tqstringlist.h>
32#include <tqguardedptr.h>
33
34class KexiProject;
35namespace Kexi
36{
37 class ObjectStatus;
38}
39
47#define KEXI_MIGRATION_VERSION_MAJOR 1
48#define KEXI_MIGRATION_VERSION_MINOR 1
49
54namespace KexiMigration
55{
56
58KEXIMIGR_EXPORT int versionMajor();
59
61KEXIMIGR_EXPORT int versionMinor();
62
63
65
78class KEXIMIGR_EXPORT KexiMigrate : public TQObject, public KexiDB::Object
79{
80 TQ_OBJECT
81
82
83 public:
84 virtual ~KexiMigrate();
85
87 KexiMigration::Data* data() const { return m_migrateData; }
88
91 void setData(KexiMigration::Data* migrateData);
92
102 bool checkIfDestinationDatabaseOverwritingNeedsAccepting(Kexi::ObjectStatus* result,
103 bool& acceptingNeeded);
104
107 bool isSourceAndDestinationDataSourceTheSame() const;
108
110 bool performImport(Kexi::ObjectStatus* result = 0);
111
113 bool performExport(Kexi::ObjectStatus* result = 0);
114
116 inline bool progressSupported() { return drv_progressSupported(); }
117
118 virtual int versionMajor() const = 0;
119 virtual int versionMinor() const = 0;
120
124 virtual TQVariant propertyValue( const TQCString& propName );
125
127 void setPropertyValue( const TQCString& propName, const TQVariant& value );
128
132 TQString propertyCaption( const TQCString& propName ) const;
133
136 TQValueList<TQCString> propertyNames() const;
137
141 virtual bool isValid();
142
143 signals:
144 void progressPercent(int percent);
145
146 protected:
148 KexiMigrate(TQObject *parent, const char *name, const TQStringList &args = TQStringList());
149
151 virtual bool drv_connect() = 0;
153 virtual bool drv_disconnect() = 0;
154
156 virtual bool drv_tableNames(TQStringList& tablenames) = 0;
157
160 const TQString& originalName, KexiDB::TableSchema& tableSchema) = 0;
161
171 virtual bool drv_queryMaxNumber(const TQString& tableName,
172 const TQString& columnName, int& result);
173
183 const TQString& sqlStatement, uint columnNumber, TQStringList& stringList,
184 int numRecords = -1)
185 { Q_UNUSED(sqlStatement); Q_UNUSED(columnNumber); Q_UNUSED(stringList);
186 Q_UNUSED(numRecords);
187 return cancelled; }
188
195 virtual tristate drv_querySingleStringFromSQL(const TQString& sqlStatement,
196 uint columnNumber, TQString& string);
197
206 virtual tristate drv_fetchRecordFromSQL(const TQString& sqlStatement,
207 KexiDB::RowData& data, bool &firstRecord)
208 { Q_UNUSED(sqlStatement); Q_UNUSED(data); Q_UNUSED(firstRecord);
209 return cancelled; }
210
214 virtual bool drv_copyTable(const TQString& srcTable, KexiDB::Connection *destConn,
215 KexiDB::TableSchema* dstTable) = 0;
216
217 virtual bool drv_progressSupported() { return false; }
218
236 virtual bool drv_getTableSize(const TQString&, TQ_ULLONG&)
237 { return false; }
238
239 void updateProgress(TQ_ULLONG step = 1ULL);
240
243 KexiDB::Field::Type userType(const TQString& fname);
244
245 virtual TQString drv_escapeIdentifier( const TQString& str ) const {
246 return m_kexiDBDriver ? m_kexiDBDriver->escapeIdentifier(str) : str; }
247
250 KexiMigration::Data* m_migrateData;
251
252// // Temporary values used during import (set by driver specific methods)
253// KexiDB::Field* m_f;
254
258 TQMap<TQCString,TQVariant> m_properties;
259
263 TQMap<TQCString,TQString> m_propertyCaptions;
264
266 TQGuardedPtr<KexiDB::Driver> m_kexiDBDriver;
267
268 private:
270 bool tableNames(TQStringList& tablenames);
271
273 TQPtrList<KexiDB::TableSchema> m_tableSchemas;
274
275 TQPtrList<KexiDB::TableSchema> m_kexiDBCompatibleTableSchemasToRemoveFromMemoryAfterImport;
276
281 bool progressInitialise();
282
283 KexiProject *m_destPrj;
284
286 TQ_ULLONG m_progressTotal;
287
289 TQ_ULLONG m_progressDone;
290
292 TQ_ULLONG m_progressNextReport;
293
294 friend class MigrateManager;
295};
296
297} //namespace KexiMigration
298
301#define KEXIMIGRATE_DRIVER_INFO( class_name, internal_name ) \
302 int class_name::versionMajor() const { return KEXI_MIGRATION_VERSION_MAJOR; } \
303 int class_name::versionMinor() const { return KEXI_MIGRATION_VERSION_MINOR; } \
304 K_EXPORT_COMPONENT_FACTORY(keximigrate_ ## internal_name, \
305 KGenericFactory<KexiMigration::class_name>( "keximigrate_" #internal_name ))
306
309#define KEXIMIGRATION_DRIVER \
310 public: \
311 virtual int versionMajor() const; \
312 virtual int versionMinor() const;
313
314#endif
315
Provides database connection, allowing queries and data modification.
Definition connection.h:62
Imports non-native databases into Kexi projects.
Definition keximigrate.h:79
TQGuardedPtr< KexiDB::Driver > m_kexiDBDriver
KexiDB driver. For instance, it is used for escaping identifiers.
virtual tristate drv_fetchRecordFromSQL(const TQString &sqlStatement, KexiDB::RowData &data, bool &firstRecord)
KexiMigrate(TQObject *parent, const char *name, const TQStringList &args=TQStringList())
Used by MigrateManager.
virtual bool drv_tableNames(TQStringList &tablenames)=0
Get table names in source database (driver specific).
virtual bool drv_readTableSchema(const TQString &originalName, KexiDB::TableSchema &tableSchema)=0
Read schema for a given table (driver specific).
bool progressSupported()
Returns true if the migration driver supports progress updates.
virtual bool drv_connect()=0
Connect to source database (driver specific).
virtual bool drv_queryMaxNumber(const TQString &tableName, const TQString &columnName, int &result)
virtual tristate drv_queryStringListFromSQL(const TQString &sqlStatement, uint columnNumber, TQStringList &stringList, int numRecords=-1)
virtual bool drv_getTableSize(const TQString &, TQ_ULLONG &)
KexiMigration::Data * data() const
Definition keximigrate.h:87
TQMap< TQCString, TQString > m_propertyCaptions
virtual bool drv_copyTable(const TQString &srcTable, KexiDB::Connection *destConn, KexiDB::TableSchema *dstTable)=0
TQMap< TQCString, TQVariant > m_properties
virtual bool drv_disconnect()=0
Disconnect from source database (driver specific).
KexiMigration::Data * m_migrateData
Migrate Options.
A project's main controller.
Definition kexiproject.h:68
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition tristate.h:100
TQValueVector< TQVariant > RowData
structure for storing single record with type information
Definition connection.h:47
Framework for importing databases into native KexiDB databases.
KEXIMIGR_EXPORT int versionMajor()
KEXIMIGR_EXPORT int versionMinor()
Namespace for general Kexi functions.
Definition kexi.h:38