int main(int argc, char *argv[]) { KAboutData aboutData("keximigratetest", 0, ki18n("Kexi Migrate Test"), "2.0"); KCmdLineArgs::init(argc, argv, &aboutData); KApplication app; KexiMigration::MigrateManager mm; kDebug() << mm.driverNames(); //Text File Test KexiMigration::KexiMigrate *m = mm.driver("Text"); KexiDB::ConnectionData cd; cd.setFileName("/home/piggz/tabdata.txt"); KexiMigration::Data d; d.source = &cd; m->setData(&d); m->connectSource(); KexiDB::TableSchema ts; if (!m->readTableSchema("tabdata.txt", ts)) { kDebug() << "Unable to read schema"; return 0; } if (!m->readFromTable("tabdata.txt")) { kDebug() << "Unable to read from table"; return 0; } while(m->moveNext()) { kDebug() << m->value(0) << m->value(1) << m->value(2); } m->movePrevious(); kDebug() << m->value(0) << m->value(1) << m->value(2); m->moveNext(); kDebug() << m->value(0) << m->value(1) << m->value(2); m->movePrevious(); kDebug() << m->value(0) << m->value(1) << m->value(2); m->movePrevious(); kDebug() << m->value(0) << m->value(1) << m->value(2); m->movePrevious(); kDebug() << m->value(0) << m->value(1) << m->value(2); m->moveNext(); kDebug() << m->value(0) << m->value(1) << m->value(2); //KSpread file test KexiMigration::KexiMigrate *k = mm.driver("KSpread"); cd.setFileName("/home/piggz/Documents/database.fods"); k->setData(&d); k->connectSource(); QStringList tn; k->tableNames(tn); kDebug() << tn; KexiDB::TableSchema ts2; if (!k->readTableSchema("Names", ts2)) { kDebug() << "Unable to read schema"; return 0; } k->readFromTable("Names"); while(k->moveNext()) { kDebug() << k->value(0) << k->value(1) << k->value(2); } }
int main(int argc, char** argv) { Q_UNUSED(argv); Q_UNUSED(argc); // first the formalities QByteArray prgname; //! TODO use KCmdLineArguments with options // first argument should be xbase source directory QString xBaseSourceDirectory = QString::fromLatin1(argv[1]); // second argument should be kexi file ( destination ) QString destinationDatabase = QString::fromLatin1(argv[2]); QFileInfo info = QFileInfo(argv[0]); prgname = info.baseName().toLatin1(); //Needed for variosu things like i18n and kconfig and stuff. No need to keep it around or clean it as this is just a test case so nothing long-lived new KComponentData(prgname); // write the code for testing migration here // Start with a driver manager KexiDB::DriverManager manager; KexiMigration::MigrateManager migrateManager; kDebug() << "Creating destination driver..."; // Get a driver to the destination database KexiDB::Driver *destDriver = manager.driver(KexiDB::defaultFileBasedDriverName() //file based ); if (!destDriver || manager.error()) { kDebug() << "Manager error..."; manager.debugError(); } KexiDB::ConnectionData *cdata; QString dbname; cdata = new KexiDB::ConnectionData(); // set destination file name here. //! TODO User should be able to specify this cdata->driverName = KexiDB::defaultFileBasedDriverName(); //! TODO User should be able to specify this dbname = destinationDatabase; cdata->setFileName(dbname); kDebug() << "Current file name: " << dbname; QString sourceDriverName = "xbase"; // get the source migration driver KexiMigration::KexiMigrate* sourceDriver = 0; sourceDriver = migrateManager.driver(sourceDriverName); if (!sourceDriver || migrateManager.error()) { kDebug() << "Import migrate driver error..."; return -1; } KexiMigration::Data* md = new KexiMigration::Data(); md->keepData = true; // delete md->destination; md->destination = new KexiProjectData(*cdata, dbname); // Setup XBase connection data KexiDB::ConnectionData* conn_data = new KexiDB::ConnectionData(); conn_data->setFileName(xBaseSourceDirectory); md->source = conn_data; md->sourceName = ""; sourceDriver->setData(md); if (!sourceDriver->performImport()) { kDebug() << "Import failed"; return -1; } return 0; }
//bool xBaseConnectionInternal::db_connect(QCString host, QCString user, // QCString password, unsigned short int port, QString socket) bool xBaseConnectionInternal::db_connect(const Predicate::ConnectionData& data) { // we have to migrate the xbase source database into a .kexi file // xbase source database directory will be in connectiondata // we can choose a KTemporaryFile for the destination .kexi file KexiMigration::MigrateManager xBase2KexiMigrateManager; // create a temporary .kexi file KTemporaryFile temporaryKexiFile; temporaryKexiFile.setSuffix( ".kexi" ); temporaryKexiFile.setAutoRemove( false ); if ( !temporaryKexiFile.open() ) { PreDrvDbg<<"Couldn't create .kexi file for exporting from xBase to .kexi"; return false; } tempDatabase = temporaryKexiFile.fileName(); Predicate::ConnectionData* kexiConnectionData = 0; kexiConnectionData = new Predicate::ConnectionData(); // set destination file name here. kexiConnectionData->driverName = Predicate::defaultFileBasedDriverName(); kexiConnectionData->setFileName( tempDatabase ); PreDrvDbg << "Current file name: " << tempDatabase; QString sourceDriverName = "xbase"; // get the source migration driver KexiMigration::KexiMigrate* sourceDriver = 0; sourceDriver = xBase2KexiMigrateManager.driver( sourceDriverName ); if(!sourceDriver || xBase2KexiMigrateManager.error()) { PreDrvDbg << "Import migrate driver error..."; return false; } KexiMigration::Data* md = new KexiMigration::Data(); md->keepData = true; md->destination = new KexiProjectData(*kexiConnectionData, tempDatabase); // Setup XBase connection data from input connection data passed //! TODO Check sanity of this md->source = new Predicate::ConnectionData(data); md->sourceName = ""; sourceDriver->setData(md); if ( !sourceDriver->performImport() ) { PreDrvDbg<<"Import failed"; return false; } // finished transferring xBase database into .kexi file // Get a driver to the destination database if ( internalDriver ) internalConn = internalDriver->createConnection(*kexiConnectionData); else return false; if (!internalConn || internalDriver->error()) { internalDriver->debugError(); return false; } if (!internalConn->connect()) { internalConn->debugError(); storeResult(); return false; } if (!internalConn->useDatabase(tempDatabase)) { internalConn->debugError(); storeResult(); return false; } // store mapping from xbase directory to .kexi file name for future use // Note: When a directory is specified ( as has to be done for xBase ), fileName() // will give directory name with an additional forward slash. dbPath() won't do so. // Need some more maintainable solution. dbMap[data.fileName()] = tempDatabase; return true; }