//!Connect to an external data source //!connStr is in the form driver|connection_string|table KexiMigrateReportData::KexiMigrateReportData(const QString & connStr) : d(new Private) { QStringList extConn = connStr.split('|'); if (extConn.size() == 3) { KexiMigration::MigrateManager mm; d->kexiMigrate = mm.driver(extConn[0]); KexiDB::ConnectionData cd; KexiMigration::Data dat; cd.setFileName(extConn[1]); dat.source = &cd; d->kexiMigrate->setData(&dat); d->valid = d->kexiMigrate->connectSource(); QStringList names; if (d->valid) { d->valid = d->kexiMigrate->readTableSchema(extConn[2], d->TableSchema); } if (d->valid) { d->schema = new KexiDB::TableOrQuerySchema(d->TableSchema); } d->valid = d->kexiMigrate->tableNames(names); if (d->valid && names.contains(extConn[2])) { d->valid = d->kexiMigrate->readFromTable(extConn[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; }
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); } }