[Kexi-devel] kdenonbeta/keximdb/src/keximdb

Jaroslaw Staniek js at iidea.pl
Fri Nov 4 20:43:20 CET 2005


SVN commit 477709 by staniek:

Update for improved Kexi Migration API
- Sample datbases like Northwind are now imported without a problem.

CCMAIL: kexi-devel at kde.org
CCMAIL: kexi at kde.org



 M  +35 -35    mdbmigrate.cpp  
 M  +25 -23    mdbmigrate.h  


--- trunk/kdenonbeta/keximdb/src/keximdb/mdbmigrate.cpp #477708:477709
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2005 Martin Ellis <martin.ellis at kdemail.net>
+   Copyright (C) 2005 Jaroslaw Staniek <js at iidea.pl>
  
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -35,11 +36,6 @@
 KEXIMIGRATE_DRIVER_INFO( MDBMigrate, mdb );
 
 /* ************************************************************************** */
-//! Constructors
-MDBMigrate::MDBMigrate()
-{
-  initBackend();
-}
 
 MDBMigrate::MDBMigrate(QObject *parent, const char *name,
                        const QStringList &args) :
@@ -118,17 +114,18 @@
 
 /* ************************************************************************** */
 /*! Get the types and properties for each column. */
-bool MDBMigrate::drv_readTableSchema(KexiDB::TableSchema& tableSchema)
+bool MDBMigrate::drv_readTableSchema(
+	const QString& originalName, KexiDB::TableSchema& tableSchema)
 {
 //moved to migration lib:  const QString tableID( KexiUtils::string2Identifier(table) );
 //  m_table = new KexiDB::TableSchema(tableID);
 //  m_table->setCaption(table);
 
   //! Get the column meta-data
-  MdbTableDef *tableDef = getTableDef(tableSchema.name());
+  MdbTableDef *tableDef = getTableDef(originalName);
   if(!tableDef) {
     kdDebug() << "MDBMigrate::drv_getTableDef: couldn't find table "
-              << tableSchema.name() << endl;
+              << originalName << endl;
     return false;
   }
   mdb_read_columns(tableDef);
@@ -229,7 +226,8 @@
 
 /*! Copy MDB table to KexiDB database */
 bool MDBMigrate::drv_copyTable(const QString& srcTable,
-                               KexiDB::TableSchema* dstTable) {
+	KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable)
+{
   QString kdLoc = "MDBMigrate::drv_copyTable: ";
   MdbTableDef *tableDef = getTableDef(srcTable);
   if(!tableDef) {
@@ -253,43 +251,45 @@
   mdb_rewind_table(tableDef);
   kdDebug() << kdLoc << "Fetching " << tableDef->num_rows << " rows" << endl;
 
-  KexiDB::Connection* dest = m_migrateData->dest;
-  KexiDB::Transaction transaction(dest->beginTransaction());
-  KexiDB::TransactionGuard tg(transaction);
+//already started in KexiMigrate:  KexiDB::Transaction transaction(destConn->beginTransaction());
 #ifdef KEXI_MIGRATION_MAX_ROWS_TO_IMPORT
   Q_ULLONG rows=0;
 #endif
-  if (!transaction.isNull()) {
-    while(mdb_fetch_row(tableDef)) {
-      QValueList<QVariant> vals = QValueList<QVariant>();
+//already started in KexiMigrate:  if (transaction.isNull())
+//already started in KexiMigrate:    return false;
 
-      kdDebug() << kdLoc << "Copying " << tableDef->num_cols << " cols" << endl;
-      for (unsigned int i = 0; i < tableDef->num_cols; i++) {
-        MdbColumn *col = (MdbColumn*) g_ptr_array_index(tableDef->columns, i);
+//already started in KexiMigrate:  KexiDB::TransactionGuard tg(transaction);
 
-        if (col->col_type == MDB_OLE && col->cur_value_len) {
-          kdDebug() << kdLoc << "OLE!! @ " << i << endl;
-          mdb_ole_read(mdb, col, columnData[i], MDB_BIND_SIZE);
-        }
+  while(mdb_fetch_row(tableDef)) {
+    QValueList<QVariant> vals = QValueList<QVariant>();
 
-        //! @todo: How to import binary data?
-        QVariant var = toQVariant(columnData[i], columnDataLength[i],
-                                col->col_type);
-        kdDebug() << kdLoc << " col=" << i 
-                << " data=" << columnData[i] 
-                << " qvar=" << var.toString() << endl;
-        vals << var;
+    kdDebug() << kdLoc << "Copying " << tableDef->num_cols << " cols" << endl;
+    for (unsigned int i = 0; i < tableDef->num_cols; i++) {
+      MdbColumn *col = (MdbColumn*) g_ptr_array_index(tableDef->columns, i);
+
+      if (col->col_type == MDB_OLE && col->cur_value_len) {
+        kdDebug() << kdLoc << "OLE!! @ " << i << endl;
+        mdb_ole_read(mdb, col, columnData[i], MDB_BIND_SIZE);
       }
-      dest->insertRecord(*dstTable, vals);
-      updateProgress();
+
+      //! @todo: How to import binary data?
+      QVariant var = toQVariant(columnData[i], columnDataLength[i],
+                              col->col_type);
+      kdDebug() << kdLoc << " col=" << i 
+              << " data=" << columnData[i] 
+              << " qvar=" << var.toString() << endl;
+      vals << var;
+    }
+    destConn->insertRecord(*dstTable, vals);
+    updateProgress();
 #ifdef KEXI_MIGRATION_MAX_ROWS_TO_IMPORT
 //! @todo this is risky when there are references between tables
-      if (++rows == KEXI_MIGRATION_MAX_ROWS_TO_IMPORT)
-        break;
+    if (++rows == KEXI_MIGRATION_MAX_ROWS_TO_IMPORT)
+      break;
 #endif
-    }
   }
-  tg.commit();
+//already started in KexiMigrate:  if (!tg.commit())
+//already started in KexiMigrate:    return false;
   //! Deallocate (unbinding) the DB columns arrays and column meta-data
   for (unsigned int i = 0; i < tableDef->num_cols; i++) {
     g_free(columnData[i]);
--- trunk/kdenonbeta/keximdb/src/keximdb/mdbmigrate.h #477708:477709
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2005 Martin Ellis <martin.ellis at kdemail.net>
+   Copyright (C) 2005 Jaroslaw Staniek <js at iidea.pl>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -31,25 +32,36 @@
 
 	class MDBMigrate : public KexiMigrate
 	{
-Q_OBJECT
-		private:
-      void initBackend();
-      void releaseBackend();
-      MdbHandle *mdb;
+		Q_OBJECT
+		
+		public:
+			MDBMigrate(QObject *parent, const char *name, const QStringList& args = QStringList());
+			virtual ~MDBMigrate();
+			
+			KexiDB::Field::Type type(int type);
+			MdbTableDef* getTableDef(const QString& tableName);
+			QVariant toQVariant(const char* data, unsigned int len, int type);
+			QVariant toDateTime(const char* data);
+			bool getPrimaryKey(KexiDB::TableSchema* table, MdbTableDef* tableDef);
+/*			
+			void MySQLMigrate::getConstraints(int mysqlConstraints, KexiDB::Field* fld);
+			void MySQLMigrate::getOptions(int flags, KexiDB::Field* fld);
+*/
 
     protected:
 			//Driver specific function to return table names
 			virtual bool drv_tableNames(QStringList& tablenames);
 			
 			//Driver specific implementation to read a table schema
-			virtual bool drv_readTableSchema(KexiDB::TableSchema& tableSchema);
+			virtual bool drv_readTableSchema(
+				const QString& originalName, KexiDB::TableSchema& tableSchema);
 			
 			//Driver specific connection implementation
 			virtual bool drv_connect();
 			virtual bool drv_disconnect();
 
-			virtual bool drv_copyTable(const QString& srcTable,
-			                           KexiDB::TableSchema* dstTable);
+			virtual bool drv_copyTable(const QString& srcTable, 
+				KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable);
 //TODO: move this somewhere to low level class (MIGRATION?)
 //			virtual bool drv_getTablesList( QStringList &list );
 //TODO: move this somewhere to low level class (MIGRATION?)
@@ -57,25 +69,15 @@
 			virtual bool drv_progressSupported() { return true; }
 			virtual bool drv_getTableSize(const QString& table, Q_ULLONG& size);
 
-		public:
-			~MDBMigrate();
-			//Constructor
-			MDBMigrate();
-			MDBMigrate(QObject *parent, const char *name, const QStringList& args = QStringList());
-			
-			KexiDB::Field::Type type(int type);
-			MdbTableDef* getTableDef(const QString& tableName);
-			QVariant toQVariant(const char* data, unsigned int len, int type);
-			QVariant toDateTime(const char* data);
-			bool getPrimaryKey(KexiDB::TableSchema* table, MdbTableDef* tableDef);
-/*			
-			void MySQLMigrate::getConstraints(int mysqlConstraints, KexiDB::Field* fld);
-			void MySQLMigrate::getOptions(int flags, KexiDB::Field* fld);
-*/
 		/*! driver's static version information, it is automatically implemented
 		 in implementation using KEXIDB_DRIVER macro (see driver_p.h) */
 		virtual int versionMajor() const;
 		virtual int versionMinor() const;
+		
+		private:
+      void initBackend();
+      void releaseBackend();
+      MdbHandle *mdb;
 	};
 }
 


More information about the Kexi-devel mailing list