//!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]);
        }
    }
}
Example #2
0
bool MDBMigrate::drv_connect()
{
    kDebug() << "mdb_open:";
    KexiDB::ConnectionData *data = this->data()->source;

    // mdb_open takes a char*, not const char*, hence this nonsense.
    char *filename = qstrdup(QFile::encodeName(data->fileName()));
    m_mdb = mdb_open(filename, MDB_NOFLAGS);
    delete [] filename;

    if (!m_mdb) {
        kWarning() << "mdb_open failed.";
        return false;
    }

    // Setting source encoding
    if (!propertyValue(nonUnicodePropId).toString().isEmpty()) {
        const QByteArray encoding(propertyValue(nonUnicodePropId).toByteArray());

        mdb_set_encoding(m_mdb, encoding.constData());
        kDebug() << "non-unicode encoding set to" << encoding;
    }

    // Supports setting source encoding
    setPropertyValue(isNonUnicodePropId, bool(IS_JET3(m_mdb)));

    return true;
}
Example #3
0
bool MDBMigrate::drv_connect()
{
    kDebug() << "mdb_open:";
    KexiDB::ConnectionData *data = m_migrateData->source;

    // mdb_open takes a char*, not const char*, hence this nonsense.
    char *filename = qstrdup(QFile::encodeName(data->fileName()));
    m_mdb = mdb_open(filename, MDB_NOFLAGS);
    delete [] filename;

    if (!m_mdb) {
        kDebug() << "mdb_open failed.";
        return false;
    }

    // Setting source encoding
    if (!m_properties[ nonUnicodePropId ].toString().isEmpty()) {
        const QByteArray encoding(m_properties[ nonUnicodePropId ].toByteArray());

        mdb_set_encoding(m_mdb, encoding.constData());
        kDebug() << "non-unicode encoding set to \""
        << encoding
        << "\"";
    }

    // Supports setting source encoding
    m_properties[ isNonUnicodePropId ] = QVariant((bool)IS_JET3(m_mdb));

    return true;
}
Example #4
0
KexiProjectData::KexiProjectData(
    const KexiDB::ConnectionData &cdata, const QString& dbname, const QString& caption)
        : QObject(0)
        , KexiDB::SchemaData()
        , formatVersion(0)
        , d(new KexiProjectDataPrivate())
{
    setObjectName("KexiProjectData");
    d->connData = cdata;
    setDatabaseName(cdata.dbFileName().isEmpty() ? dbname : cdata.dbFileName());
    setCaption(caption);
}
Example #5
0
/*! Connect to the db backend */
bool xBaseMigrate::drv_connect()
{
  // Get the xbase directory path
  Data* migrationData = data();
  KexiDB::ConnectionData* dataSource = migrationData->source;
  QString dbPath = dataSource->dbPath();

  QDir xBaseDirectory( dbPath );

  // set filters
  QStringList dbfFilters;
//! @todo use application/x-dbase mime type as soon as share mime db provides info on file extensions
  dbfFilters<<"*.dbf"<<"*.DBF";

  xBaseDirectory.setNameFilters( dbfFilters );
  QStringList dbfFiles = xBaseDirectory.entryList(); // set a readable files filter here ?

  foreach( const QString& fileName, dbfFiles ) {
    xbDbf* table = new xbDbf( this );
    // Calling OpenDatabase, will automatically add the pointer `table`
    // to the dbfList of xbXBase class ( if there is no error )
    QString absoluteFileName = xBaseDirectory.filePath( fileName );

    // remove the letters '.dbf'. Hence the -4
    QString choppedFileName = fileName.left( fileName.length() - 4 ).toLower();
    m_tableNamePathMap[choppedFileName] = absoluteFileName;
    kDebug()<<choppedFileName<<" Path:"<<absoluteFileName;

    int returnCode;
    QByteArray ba = absoluteFileName.toUtf8();
    if (  ( returnCode = table->OpenDatabase( ba.constData() ) ) != XB_NO_ERROR ) {
      switch( returnCode ) {
        case XB_OPEN_ERROR:
          kDebug()<<"Couldn't open "<<absoluteFileName<<".Skipping it.";
          break;
        case XB_NO_MEMORY:
          kDebug()<<"Memory allocation error in XBase library";
          return false;
        case XB_NOT_XBASE:
          kDebug()<<absoluteFileName<<" is not a DBF file.Skipping it.";
          break;
        default:
          kDebug()<<"Error code "<<returnCode;
          return false;
      }
    }
  }
void KexiWelcomeAssistant::openProjectOrShowPasswordPage(KexiProjectData *data)
{
    KexiDB::ConnectionData *cdata = data->connectionData();
    if (cdata) {
        if (cdata->passwordNeeded()) {
            d->projectData = data;
            d->passwordPage()->setConnectionData(*cdata);
            d->passwordPage()->showDatabaseName(true);
            d->passwordPage()->setDatabaseNameReadOnly(true);
            d->passwordPage()->setDatabaseName(data->databaseName());
            setCurrentPage(d->passwordPage());
            return;
        }
        else {
            d->projectData = 0;
            emitOpenProject(data);
        }
    }

}
Example #7
0
bool KexiMigrate::isSourceAndDestinationDataSourceTheSame() const
{
    KexiDB::ConnectionData* sourcedata = m_migrateData->source;
    KexiDB::ConnectionData* destinationdata = m_migrateData->destination->connectionData();
    return (
               sourcedata && destinationdata &&
               m_migrateData->sourceName == m_migrateData->destination->databaseName() && // same database name
               sourcedata->driverName == destinationdata->driverName && // same driver
               sourcedata->hostName == destinationdata->hostName && // same host
               sourcedata->fileName() == destinationdata->fileName() && // same filename
               sourcedata->dbPath() == destinationdata->dbPath() && // same database path
               sourcedata->dbFileName() == destinationdata->dbFileName() // same database filename
           );
}
Example #8
0
bool SQLiteAdminTools::vacuum(const KexiDB::ConnectionData& data, const QString& databaseName)
{
    clearError();
    KexiDB::DriverManager manager;
    KexiDB::Driver *drv = manager.driver(data.driverName);
    QString title(i18n("Could not compact database \"%1\".", QDir::toNativeSeparators(databaseName)));
    if (!drv) {
        setError(&manager, title);
        return false;
    }
    SQLiteVacuum vacuum(data.dbPath() + QDir::separator() + databaseName);
    tristate result = vacuum.run();
    if (!result) {
        setError(title);
        return false;
    } else //success or cancelled
        return true;
}
Example #9
0
ConnectionTestDialog::ConnectionTestDialog(QWidget* parent,
        const KexiDB::ConnectionData& data,
        KexiDB::MessageHandler& msgHandler)
        : KProgressDialog(parent,
                          i18n("Test Connection"),
                          i18n("<qt>Testing connection to <b>%1</b> database server...</qt>",
                               data.serverInfoString(true))
                         )
        , m_thread(new ConnectionTestThread(this, data))
        , m_connData(data)
        , m_msgHandler(&msgHandler)
        , m_elapsedTime(0)
        , m_errorObj(0)
        , m_stopWaiting(false)
{
    setModal(true);
    showCancelButton(true);
    progressBar()->setFormat(""); //hide %
    progressBar()->setRange(0, 0); //to show busy indicator
    connect(&m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
    adjustSize();
    resize(250, height());
}
Example #10
0
KexiMigrate* ImportWizard::prepareImport(Kexi::ObjectStatus& result)
{
	KexiUtils::WaitCursor wait;
	
	// Start with a driver manager
	KexiDB::DriverManager manager;

	kdDebug() << "Creating destination driver..." << endl;

	// Get a driver to the destination database
	KexiDB::Driver *destDriver = manager.driver(
		m_dstConn->selectedConnectionData() ? m_dstConn->selectedConnectionData()->driverName //server based
		 : KexiDB::Driver::defaultFileBasedDriverName()
		// : m_dstTypeCombo->currentText() //file based
	);
	if (!destDriver || manager.error())
	{
		result.setStatus(&manager);
		kdDebug() << "Manager error..." << endl;
		manager.debugError();
//		result.setStatus(&manager);
	}

	// Set up destination connection data
	KexiDB::ConnectionData *cdata;
	bool cdataOwned = false;
	QString dbname;
	if (!result.error())
	{
		if (m_dstConn->selectedConnectionData())
		{
			//server-based project
			kdDebug() << "Server destination..." << endl;
			cdata = m_dstConn->selectedConnectionData();
			dbname = m_dstNewDBNameLineEdit->text();
		}
		else // if (m_dstTypeCombo->currentText().lower() == KexiDB::Driver::defaultFileBasedDriverName()) 
		{
			//file-based project
			kdDebug() << "File Destination..." << endl;
			cdata = new KexiDB::ConnectionData();
			cdataOwned = true;
			cdata->caption = m_dstNewDBNameLineEdit->text();
			cdata->driverName = KexiDB::Driver::defaultFileBasedDriverName();
			dbname = m_dstConn->selectedFileName();
			cdata->setFileName( dbname );
			kdDebug() << "Current file name: " << dbname << endl;
		}
/*		else
		{
			//TODO This needs a better message
			//KMessageBox::error(this, 
			result.setStatus(i18n("No connection data is available. You did not select a destination filename."),"");
			//return false;
		} */
	}

	// Find a source (migration) driver name
	QString sourceDriverName;
	if (!result.error())
	{
		sourceDriverName = driverNameForSelectedSource();
		if (sourceDriverName.isEmpty())
			result.setStatus(i18n("No appropriate migration driver found."), 
				m_migrateManager.possibleProblemsInfoMsg());
	}

	// Get a source (migration) driver
	KexiMigrate* sourceDriver = 0;
	if (!result.error())
	{
		sourceDriver = m_migrateManager.driver( sourceDriverName );
		if(!sourceDriver || m_migrateManager.error()) {
			kdDebug() << "Import migrate driver error..." << endl;
			result.setStatus(&m_migrateManager);
		}
	}

	KexiUtils::removeWaitCursor();

	// Set up source (migration) data required for connection
	if (sourceDriver && !result.error())
	{
		// Setup progress feedback for the GUI
		if(sourceDriver->progressSupported()) {
			m_progressBar->updateGeometry();
			disconnect(sourceDriver, SIGNAL(progressPercent(int)), 
				this, SLOT(progressUpdated(int)));
			connect(sourceDriver, SIGNAL(progressPercent(int)),
				this, SLOT(progressUpdated(int)));
			progressUpdated(0);
		}

		bool keepData;
		if (m_importTypeButtonGroup->selectedId() == 0)
		{
			kdDebug() << "Structure and data selected" << endl;
			keepData = true;
		}
		else if (m_importTypeButtonGroup->selectedId() == 1)
		{
			kdDebug() << "structure only selected" << endl;
			keepData = false;
		}
		else
		{
			kdDebug() << "Neither radio button is selected (not possible?) presume keep data" << endl;
			keepData = true;
		}
		
		KexiMigration::Data* md = new KexiMigration::Data();
	//	delete md->destination;
		md->destination = new KexiProjectData(*cdata, dbname);
		if(fileBasedSrcSelected()) {
			KexiDB::ConnectionData* conn_data = new KexiDB::ConnectionData();
			conn_data->setFileName(m_srcConn->selectedFileName());
			md->source = conn_data;
			md->sourceName = "";
		}
		else 
		{
			if (m_predefinedConnectionData)
				md->source = m_predefinedConnectionData;
			else
				md->source = m_srcConn->selectedConnectionData();

			if (!m_predefinedDatabaseName.isEmpty())
				md->sourceName = m_predefinedDatabaseName;
			else
				md->sourceName = m_srcDBName->selectedProjectData()->databaseName();
	//! @todo Aah, this is so C-like. Move to performImport().
		}
		md->keepData = keepData;
		sourceDriver->setData(md);
		return sourceDriver;
	}
Example #11
0
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;
}
Example #12
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);
    }
}