Kexi API Documentation (2.0 alpha)

KexiMigration::KexiMigrate Class Reference

#include <keximigrate.h>

Inheritance diagram for KexiMigration::KexiMigrate:

KexiDB::Object KexiMigration::MySQLMigrate KexiMigration::PqxxMigrate KexiMigration::TxtMigrate List of all members.

Detailed Description

Imports non-native databases into Kexi projects.

A generic API for importing schema and data from an existing database into a new Kexi project. Can be also used for importing native Kexi databases.

Basic idea is this:

  1. User selects an existing DB and new project (file or server based)
  2. User specifies whether to import structure and data or structure only.
  3. Import tool connects to db
  4. Checks if it is already a kexi project (not implemented yet)
  5. If not, then read structure and construct new project
  6. Ask user what to do if column type is not supported

See kexi/doc/dev/kexi_import.txt for more info.

Definition at line 78 of file keximigrate.h.

Signals

void progressPercent (int percent)

Public Member Functions

virtual ~KexiMigrate ()
KexiMigration::Datadata () const
void setData (KexiMigration::Data *migrateData)
 Data Setup. Requires two connection objects, a name and a bool.
bool checkIfDestinationDatabaseOverwritingNeedsAccepting (Kexi::ObjectStatus *result, bool &acceptingNeeded)
bool isSourceAndDestinationDataSourceTheSame () const
bool performImport (Kexi::ObjectStatus *result=0)
 Perform an import operation.
bool performExport (Kexi::ObjectStatus *result=0)
 Perform an export operation.
bool progressSupported ()
 Returns true if the migration driver supports progress updates.
virtual int versionMajor () const =0
virtual int versionMinor () const =0
virtual QVariant propertyValue (const QCString &propName)
void setPropertyValue (const QCString &propName, const QVariant &value)
QString propertyCaption (const QCString &propName) const
QValueList< QCString > propertyNames () const
virtual bool isValid ()

Protected Member Functions

 KexiMigrate (QObject *parent, const char *name, const QStringList &args=QStringList())
 Used by MigrateManager.
virtual bool drv_connect ()=0
 Connect to source database (driver specific).
virtual bool drv_disconnect ()=0
 Disconnect from source database (driver specific).
virtual bool drv_tableNames (QStringList &tablenames)=0
 Get table names in source database (driver specific).
virtual bool drv_readTableSchema (const QString &originalName, KexiDB::TableSchema &tableSchema)=0
 Read schema for a given table (driver specific).
virtual bool drv_queryMaxNumber (const QString &tableName, const QString &columnName, int &result)
virtual tristate drv_queryStringListFromSQL (const QString &sqlStatement, uint columnNumber, QStringList &stringList, int numRecords=-1)
virtual tristate drv_querySingleStringFromSQL (const QString &sqlStatement, uint columnNumber, QString &string)
virtual tristate drv_fetchRecordFromSQL (const QString &sqlStatement, KexiDB::RowData &data, bool &firstRecord)
virtual bool drv_copyTable (const QString &srcTable, KexiDB::Connection *destConn, KexiDB::TableSchema *dstTable)=0
 Copy a table from source DB to target DB (driver specific)
  • create copies of KexiDB tables
  • create copies of non-KexiDB tables.

virtual bool drv_progressSupported ()
virtual bool drv_getTableSize (const QString &, Q_ULLONG &)
void updateProgress (Q_ULLONG step=1ULL)
KexiDB::Field::Type userType (const QString &fname)
 Prompt user to select a field type for unrecognized fields.
virtual QString drv_escapeIdentifier (const QString &str) const

Protected Attributes

KexiMigration::Datam_migrateData
 Migrate Options.
QMap< QCString, QVariant > m_properties
QMap< QCString, QStringm_propertyCaptions
QGuardedPtr< KexiDB::Driverm_kexiDBDriver
 KexiDB driver. For instance, it is used for escaping identifiers.

Friends

class MigrateManager


Constructor & Destructor Documentation

KexiMigrate::~KexiMigrate  )  [virtual]
 

Definition at line 59 of file keximigrate.cpp.

KexiMigrate::KexiMigrate QObject *  parent,
const char *  name,
const QStringList &  args = QStringList()
[protected]
 

Used by MigrateManager.

Definition at line 36 of file keximigrate.cpp.


Member Function Documentation

bool KexiMigrate::checkIfDestinationDatabaseOverwritingNeedsAccepting Kexi::ObjectStatus result,
bool &  acceptingNeeded
 

Checks whether the destination database exists. For file-based dest. projects, we've already asked about overwriting existing project but for server-based projects it's better to ask user. This method should be called before performImport() or performExport().

Returns:
true if no connection-related errors occurred. acceptingNeeded is set to true if destination database exists. In this case you should ask about accepting database overwriting. Used in ImportWizard::import().

Definition at line 64 of file keximigrate.cpp.

References Kexi::ObjectStatus::clearStatus(), KexiDB::Connection::connect(), KexiProjectData::connectionData(), KexiDB::Driver::createConnection(), KexiDB::Connection::databaseExists(), KexiProjectData::databaseName(), KexiMigration::Data::destination, KexiDB::Connection::disconnect(), KexiDB::DriverManager::driver(), KexiDB::Object::error(), KexiDB::Driver::isFileDriver(), m_migrateData, and Kexi::ObjectStatus::setStatus().

KexiMigration::Data* KexiMigration::KexiMigrate::data  )  const [inline]
 

Todo:
Remove this! KexiMigrate should be usable for multiple concurrent migrations!

Definition at line 86 of file keximigrate.h.

Referenced by performImport().

virtual bool KexiMigration::KexiMigrate::drv_connect  )  [protected, pure virtual]
 

Connect to source database (driver specific).

Implemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Referenced by performImport().

virtual bool KexiMigration::KexiMigrate::drv_copyTable const QString srcTable,
KexiDB::Connection destConn,
KexiDB::TableSchema dstTable
[protected, pure virtual]
 

Copy a table from source DB to target DB (driver specific)

  • create copies of KexiDB tables
  • create copies of non-KexiDB tables.

Implemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Referenced by performImport().

virtual bool KexiMigration::KexiMigrate::drv_disconnect  )  [protected, pure virtual]
 

Disconnect from source database (driver specific).

Implemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Referenced by performImport().

virtual QString KexiMigration::KexiMigrate::drv_escapeIdentifier const QString str  )  const [inline, protected, virtual]
 

Definition at line 240 of file keximigrate.h.

Referenced by KexiMigration::MySQLMigrate::drv_copyTable(), KexiMigration::MySQLMigrate::drv_getTableSize(), drv_queryMaxNumber(), KexiMigration::MySQLMigrate::drv_readTableSchema(), KexiMigration::MySQLMigrate::examineBlobField(), and KexiMigration::MySQLMigrate::examineEnumField().

virtual tristate KexiMigration::KexiMigrate::drv_fetchRecordFromSQL const QString sqlStatement,
KexiDB::RowData data,
bool &  firstRecord
[inline, protected, virtual]
 

Fetches single record from result obtained by running sqlStatement. firstRecord should be first initialized to true, so the method can run the query at first call and then set it will set firstRecord to false, so subsequent calls will only fetch records. On success the result is stored in data and true is returned, data is resized to appropriate size. cancelled is returned on EOF.

Todo:
SQL-dependent!

Reimplemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Definition at line 202 of file keximigrate.h.

References cancelled.

Referenced by performImport().

virtual bool KexiMigration::KexiMigrate::drv_getTableSize const QString ,
Q_ULLONG & 
[inline, protected, virtual]
 

Returns:
the size of a table to be imported, or 0 if not supported Finds the size of the named table, in order to provide feedback on migration progress.
The units of the return type are deliberately unspecified. Migration drivers may return the number of records in the table, or the size in bytes, etc. Units should be chosen in order that the driver can return the size in the fastest way possible (e.g. migration from CSV files should use file size to avoid counting the number of rows, and migration from MDB files should return the number of rows as this is stored within the file).

Obviously, the driver should use the same units when reporting migration progress.

Returns:
size of the specified table

Reimplemented in KexiMigration::MySQLMigrate.

Definition at line 231 of file keximigrate.h.

virtual bool KexiMigration::KexiMigrate::drv_progressSupported  )  [inline, protected, virtual]
 

Reimplemented in KexiMigration::MySQLMigrate.

Definition at line 212 of file keximigrate.h.

Referenced by performImport().

bool KexiMigrate::drv_queryMaxNumber const QString tableName,
const QString columnName,
int &  result
[protected, virtual]
 

Fetches maximum number from table tableName, column columnName into result. On success true is returned. If there is no records in the table, result is set to 0 and true is returned.

  • Note 1: implement only if the database can already contain kexidb__* tables (so e.g. keximdb driver doea not need this).
  • Note 2: default implementation uses drv_querySingleStringFromSQL() with "SELECT MAX(columName) FROM tableName" statement, assuming SQL-compliant backend.

Definition at line 586 of file keximigrate.cpp.

References drv_escapeIdentifier(), and drv_querySingleStringFromSQL().

tristate KexiMigrate::drv_querySingleStringFromSQL const QString sqlStatement,
uint  columnNumber,
QString string
[protected, virtual]
 

Fetches single string at column columnNumber from result obtained by running sqlStatement. On success the result is stored in string and true is returned.

Returns:
cancelled if there are no records available. This implementation uses drv_queryStringListFromSQL() with numRecords == 1.
Todo:
SQL-dependent!

Definition at line 606 of file keximigrate.cpp.

References drv_queryStringListFromSQL().

Referenced by drv_queryMaxNumber().

virtual tristate KexiMigration::KexiMigrate::drv_queryStringListFromSQL const QString sqlStatement,
uint  columnNumber,
QStringList &  stringList,
int  numRecords = -1
[inline, protected, virtual]
 

Fetches single string at column columnNumber for each record from result obtained by running sqlStatement. numRecords can be specified to limit number of records read. If numRecords is -1, all records are loaded. On success the result is stored in stringList and true is returned.

Returns:
cancelled if there are no records available.
  • Note: implement only if the database can already contain kexidb__* tables (so e.g. keximdb driver does not need this).
Todo:
SQL-dependent!

Reimplemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Definition at line 181 of file keximigrate.h.

References cancelled.

Referenced by drv_querySingleStringFromSQL(), and performImport().

virtual bool KexiMigration::KexiMigrate::drv_readTableSchema const QString originalName,
KexiDB::TableSchema tableSchema
[protected, pure virtual]
 

Read schema for a given table (driver specific).

Implemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

Referenced by performImport().

virtual bool KexiMigration::KexiMigrate::drv_tableNames QStringList &  tablenames  )  [protected, pure virtual]
 

Get table names in source database (driver specific).

Implemented in KexiMigration::MySQLMigrate, and KexiMigration::PqxxMigrate.

bool KexiMigrate::isSourceAndDestinationDataSourceTheSame  )  const
 

Checks if the source- and the destination databases are identical.

Returns:
true if they are identical else false.

Definition at line 99 of file keximigrate.cpp.

References KexiProjectData::connectionData(), KexiProjectData::databaseName(), KexiDB::ConnectionData::dbFileName(), KexiDB::ConnectionData::dbPath(), KexiMigration::Data::destination, KexiDB::ConnectionDataBase::driverName, KexiDB::ConnectionData::fileName(), KexiDB::ConnectionDataBase::hostName, m_migrateData, KexiMigration::Data::source, and KexiMigration::Data::sourceName.

bool KexiMigrate::isValid  )  [virtual]
 

Returns:
true is driver is valid. Checks if KexiMigrate::versionMajor() and KexiMigrate::versionMinor() are matching. You can reimplement this but always call KexiMigrate::isValid() implementation.

Definition at line 571 of file keximigrate.cpp.

References ERR_INCOMPAT_DRIVER_VERSION, KexiDB::Object::setError(), versionMajor(), KexiMigration::versionMajor(), versionMinor(), and KexiMigration::versionMinor().

Referenced by KexiMigration::MigrateManagerInternal::driver().

bool KexiMigrate::performExport Kexi::ObjectStatus result = 0  ) 
 

Perform an export operation.

Todo:
performExport

Definition at line 423 of file keximigrate.cpp.

bool KexiMigrate::performImport Kexi::ObjectStatus result = 0  ) 
 

Perform an import operation.

Todo:
to reuse Connection::setupTableSchema()'s statement somehow...
Todo:
check detailed "copy forms/blobs/tables" flags here when we add them
Todo:
what if these two tables are not compatible with tables created in destination db because newer db format was used?
Todo:
copy kexi__db contents!

Definition at line 116 of file keximigrate.cpp.

References KexiDB::FieldList::addField(), KexiDB::Connection::beginTransaction(), Kexi::ObjectStatus::clearStatus(), KexiDB::Connection::commitTransaction(), KexiProjectData::connectionData(), KexiProject::create(), KexiDB::Connection::createTable(), data(), KexiProjectData::databaseName(), KexiProject::dbConnection(), KexiDB::Object::debugError(), KexiMigration::Data::destination, KexiDB::Connection::disconnect(), KexiDB::Connection::driver(), KexiDB::DriverManager::driver(), KexiDB::Connection::dropDatabase(), drv_connect(), drv_copyTable(), KexiDB::Connection::drv_createTable(), drv_disconnect(), drv_fetchRecordFromSQL(), drv_progressSupported(), drv_queryStringListFromSQL(), drv_readTableSchema(), KexiProject::error(), foreach, KexiDB::SchemaData::id(), KexiDB::Transaction::isNull(), KexiDB::Driver::isSystemObjectName(), KexiMigration::Data::keepData, m_migrateData, KexiDB::SchemaData::name(), NUM_OF_ROWS_PER_CREATE_TABLE, KexiDB::Connection::rollbackTransaction(), KexiDB::ConnectionData::serverInfoString(), KexiDB::SchemaData::setCaption(), Kexi::ObjectStatus::setStatus(), KexiDB::Connection::setupField(), KexiDB::Connection::setupObjectSchemaData(), KexiMigration::Data::source, KexiUtils::string2Identifier(), KexiDB::TableObjectType, KexiDB::Connection::tableSchema(), tname(), and updateProgress().

void KexiMigration::KexiMigrate::progressPercent int  percent  )  [signal]
 

Referenced by updateProgress().

bool KexiMigration::KexiMigrate::progressSupported  )  [inline]
 

Returns true if the migration driver supports progress updates.

Definition at line 115 of file keximigrate.h.

QString KexiMigrate::propertyCaption const QCString &  propName  )  const
 

Returns:
translated property caption for propeName. If there's no such property defined for driver, empty string value is returned.

Definition at line 554 of file keximigrate.cpp.

References m_propertyCaptions.

QValueList< QCString > KexiMigrate::propertyNames  )  const
 

Todo:
This is copied from KexiDB::Driver.
One day it will be merged with KexiDB.
Returns:
a list of property names available for this driver.

Definition at line 564 of file keximigrate.cpp.

References m_properties.

QVariant KexiMigrate::propertyValue const QCString &  propName  )  [virtual]
 

Returns:
property value for propeName available for this driver. If there's no such property defined for driver, Null QVariant value is returned.

Definition at line 549 of file keximigrate.cpp.

References m_properties.

void KexiMigrate::setData KexiMigration::Data migrateData  ) 
 

Data Setup. Requires two connection objects, a name and a bool.

Todo:
Remove this! KexiMigrate should be usable for multiple concurrent migrations!

Definition at line 52 of file keximigrate.cpp.

References m_migrateData.

void KexiMigrate::setPropertyValue const QCString &  propName,
const QVariant &  value
 

Todo:
This is copied from KexiDB::Driver. One day it will be merged with KexiDB.

Definition at line 559 of file keximigrate.cpp.

References m_properties.

void KexiMigrate::updateProgress Q_ULLONG  step = 1ULL  )  [protected]
 

Definition at line 478 of file keximigrate.cpp.

References progressPercent().

Referenced by KexiMigration::PqxxMigrate::drv_copyTable(), KexiMigration::MySQLMigrate::drv_copyTable(), and performImport().

KexiDB::Field::Type KexiMigrate::userType const QString fname  )  [protected]
 

Prompt user to select a field type for unrecognized fields.

Todo:
user should be asked ONCE using a convenient wizard's page, not a popup dialog

Definition at line 492 of file keximigrate.cpp.

References KexiDB::Field::BigInteger, KexiDB::Field::BLOB, KexiDB::Field::Boolean, KexiDB::Field::Byte, KexiDB::Field::Date, KexiDB::Field::DateTime, KexiDB::Field::Double, KexiDB::Field::Float, KexiDB::Field::Integer, KexiDB::Field::LongText, KexiDB::Field::ShortInteger, KexiDB::Field::Text, and KexiDB::Field::Time.

Referenced by KexiMigration::MySQLMigrate::type().

virtual int KexiMigration::KexiMigrate::versionMajor  )  const [pure virtual]
 

Referenced by isValid().

virtual int KexiMigration::KexiMigrate::versionMinor  )  const [pure virtual]
 

Referenced by isValid().


Friends And Related Function Documentation

friend class MigrateManager [friend]
 

Definition at line 289 of file keximigrate.h.


Member Data Documentation

QGuardedPtr<KexiDB::Driver> KexiMigration::KexiMigrate::m_kexiDBDriver [protected]
 

KexiDB driver. For instance, it is used for escaping identifiers.

Definition at line 261 of file keximigrate.h.

KexiMigration::Data* KexiMigration::KexiMigrate::m_migrateData [protected]
 

Migrate Options.

Todo:
Remove this! KexiMigrate should be usable for multiple concurrent migrations!

Definition at line 245 of file keximigrate.h.

Referenced by checkIfDestinationDatabaseOverwritingNeedsAccepting(), KexiMigration::PqxxMigrate::drv_connect(), KexiMigration::MySQLMigrate::drv_connect(), isSourceAndDestinationDataSourceTheSame(), performImport(), and setData().

QMap<QCString,QVariant> KexiMigration::KexiMigrate::m_properties [protected]
 

Driver properties dictionary (indexed by name), useful for presenting properties to the user. Set available properties here in driver implementation.

Definition at line 253 of file keximigrate.h.

Referenced by propertyNames(), propertyValue(), and setPropertyValue().

QMap<QCString,QString> KexiMigration::KexiMigrate::m_propertyCaptions [protected]
 

i18n'd captions for properties. You do not need to set predefined properties' caption in driver implementation -it's done automatically.

Definition at line 258 of file keximigrate.h.

Referenced by propertyCaption().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for Kexi 2.0 alpha.
Documentation copyright © 2002-2007 the Kexi Team.
Generated on Tue Apr 1 20:50:51 2008 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003