[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kexi/migration
From:       Adam Pigg <adam () piggz ! fsnet ! co ! uk>
Date:       2005-02-09 21:50:24
Message-ID: 20050209215024.A9EEA1CFBB () office ! kde ! org
[Download RAW message or body]

CVS commit by piggz: 

Added feature 'data copy' with import.  This needs another page in the wizard.


  M +1 -1      importwizard.cpp   1.19
  M +7 -5      keximigrate.cpp   1.11
  M +374 -321  pqxx/pqxxmigrate.cpp   1.6


--- koffice/kexi/migration/pqxx/pqxxmigrate.cpp  #1.5:1.6
@@ -23,4 +23,9 @@
 #include <qstring.h>
 #include <kdebug.h>
+#include <qstringlist.h>
+
+//I maybe shouldnt use stl?
+#include <string>
+#include <vector>
 
 #include "./kexidb/cursor.h"
@@ -42,7 +47,7 @@ KEXIMIGRATE_DRIVER_INFO( pqxxMigrate, pq
 pqxxMigrate::pqxxMigrate()
 {
-m_res=0;
-m_trans=0;
-m_conn=0;
+    m_res=0;
+    m_trans=0;
+    m_conn=0;
 }
 
@@ -50,7 +55,7 @@ pqxxMigrate::pqxxMigrate(QObject *parent
   KexiMigrate(parent, name, args)
 {
-m_res=0;
-m_trans=0;
-m_conn=0;
+    m_res=0;
+    m_trans=0;
+    m_conn=0;
 }
 //==================================================================================
@@ -388,8 +393,56 @@ bool pqxxMigrate::primaryKey(pqxx::oid t
 }
 
+//=========================================================================
 /*! Copy PostgreSQL table to KexiDB database */
 bool pqxxMigrate::drv_copyTable(const QString& srcTable,
-                                KexiDB::TableSchema* dstTable) {
+                                KexiDB::TableSchema* dstTable)
+{
+    std::vector<std::string> R;
+
+    pqxx::work T(*m_conn, "pqxxMigrate::drv_copyTable");
+
+    pqxx::tablereader stream(T, (srcTable.latin1()));
+
+    //Loop round each row, reading into a vector of strings
+    for (int n=0; (stream >> R); ++n)
+    {
+        QValueList<QVariant> vals = QValueList<QVariant>();
+        for (std::vector<std::string>::const_iterator i = R.begin(); i != R.end(); \
++i) +        {
+            QVariant var = QVariant((*i).c_str());
+            vals << var;
+        }
+
+        m_kexiDB->insertRecord(*dstTable, vals);
+    }
+
+    stream.complete();
+
         return true;
+
+
+    //It could be done this way (with some altering):
+    /*
+    if(query("SELECT * FROM " + d->escapeIdentifier(srcTable)))
+      {
+
+          for (pqxx::result::const_iterator c = m_res->begin(); c != m_res->end(); \
++c) +          {
+              int numFields = mysql_num_fields(res);
+              QValueList<QVariant> vals = QValueList<QVariant>();
+              for(int i = 0; i < numFields; i++)
+              {
+                  QVariant var = QVariant(row[i]);
+                  vals << var;
+              }
+              m_kexiDB->insertRecord(*dstTable, vals);
+          }
+          return true;
+      }
+      else
+      {
+          return false;
+      }
+    */
 }
 

--- koffice/kexi/migration/importwizard.cpp  #1.18:1.19
@@ -324,5 +324,5 @@ void importWizard::accept()
     
     kdDebug() << "Setting import data.." << endl;
-    import->setData(srcConn->selectedConnectionData(), \
srcdbname->selectedProjectData()->databaseName(), kexi_conn, dbname, false); +    \
import->setData(srcConn->selectedConnectionData(), \
srcdbname->selectedProjectData()->databaseName(), kexi_conn, dbname, true);  
     kdDebug() << "Performing import..." << endl;

--- koffice/kexi/migration/keximigrate.cpp  #1.10:1.11
@@ -66,6 +66,8 @@ bool KexiMigrate::performImport()
         
         //Step 1 - connect
+        kdDebug() << "MIGRATE TEST CONNECTING..." << endl;
         if (drv_connect())
         {
+                kdDebug() << "MIGRATE TEST GETTING TABLENAMES..." << endl;
                 //Step 2 - get table names
                 if (tableNames(tables))
@@ -126,9 +128,9 @@ bool KexiMigrate::performImport()
                 }
         }
-else
-{
+        else
+        {
         kdDebug() << "Couldnt connect to database server" << endl;
         return false;
-}
+        }
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic