From kde-commits Thu Sep 07 22:18:21 2006 From: Martin Ellis Date: Thu, 07 Sep 2006 22:18:21 +0000 To: kde-commits Subject: kdenonbeta/keximdb Message-Id: <1157667501.441104.561.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=115766751902039 SVN commit 581914 by martin: A wee tidy-up for KOffice 1.6. M +2 -2 build_keximdb_tarball.sh M +1 -1 debian/control M +66 -55 src/keximdb/mdbmigrate.cpp --- trunk/kdenonbeta/keximdb/build_keximdb_tarball.sh #581913:581914 @@ -1,5 +1,5 @@ #!/bin/sh -VERSION=1.0.1 +VERSION=1.1.0 DESTINATION=/tmp/keximdb-dist/$VERSION/ KDESVN=svn://anonsvn.kde.org/home/kde @@ -9,7 +9,7 @@ BRANCH=trunk/kdenonbeta # From release branch -#BRANCH=branches/work/keximdb/koffice-1.5 +#BRANCH=branches/work/keximdb/koffice-1.6 ######### set -e --- trunk/kdenonbeta/keximdb/debian/control #581913:581914 @@ -1,7 +1,7 @@ Source: keximdb Priority: optional Maintainer: Martin Ellis -Build-Depends: debhelper (>= 4.0.0), autotools-dev, koffice-dev (>= 1:1.5.2-1), koffice-dev (<< 1:1.5.90), libglib2.0-dev +Build-Depends: debhelper (>= 4.0.0), autotools-dev, koffice-dev (>= 1:1.6.0), libglib2.0-dev Standards-Version: 3.7.2 Section: kde --- trunk/kdenonbeta/keximdb/src/keximdb/mdbmigrate.cpp #581913:581914 @@ -1,17 +1,17 @@ /* This file is part of the KDE project Copyright (C) 2005,2006 Martin Ellis Copyright (C) 2005 Jaroslaw Staniek - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -35,17 +35,22 @@ /* This is the implementation for the MDB file import routines. */ KEXIMIGRATE_DRIVER_INFO( MDBMigrate, mdb ); +static QCString isNonUnicodePropId( "source_database_has_nonunicode_encoding" ); +static QCString nonUnicodePropId( "source_database_nonunicode_encoding" ); + /* ************************************************************************** */ MDBMigrate::MDBMigrate(QObject *parent, const char *name, const QStringList &args) : - KexiMigrate(parent, name, args) + KexiMigrate(parent, name, args) { - m_properties["source_database_has_nonunicode_encoding"] = QVariant( true, 1 ); - m_propertyCaptions["source_database_has_nonunicode_encoding"] - = i18n("Source Database Has Non-Unicode Encoding"); - m_properties["source_database_nonunicode_encoding"] = QVariant(""); - m_propertyCaptions["source_database_nonunicode_encoding"] + + /*! @todo invert the sense of values, then remove "Non-" from these strings */ + m_properties[ isNonUnicodePropId ] = QVariant( true, 1 ); + m_propertyCaptions[ isNonUnicodePropId ] = + i18n("Source Database Has Non-Unicode Encoding"); + m_properties[ nonUnicodePropId ] = QVariant(""); + m_propertyCaptions[ nonUnicodePropId ] = i18n("Source Database Non-Unicode Encoding"); initBackend(); @@ -72,11 +77,14 @@ mdb_exit(); } +/* ************************************************************************** */ +/*! Properties */ QVariant MDBMigrate::propertyValue( const QCString& propName ) { - if (propName == "source_database_has_nonunicode_encoding") { - m_properties["source_database_has_nonunicode_encoding"] = QVariant(false, 0); - //costly, but we need this to get this property from file... + if ( propName == isNonUnicodePropId ) { + m_properties[ isNonUnicodePropId ] = QVariant(false, 0); + + // Costly, but we need this to get this property from file... drv_connect(); drv_disconnect(); } @@ -100,23 +108,27 @@ return false; } - //setting source encoding - if (!m_properties["source_database_nonunicode_encoding"].toCString().isEmpty()) { - mdb_set_encoding(m_mdb, (const char*)m_properties["source_database_nonunicode_encoding"].toCString()); - kdDebug() << "non-unicode encoding set to \"" << m_properties["source_database_nonunicode_encoding"].toCString() << "\"" << endl; + // Setting source encoding + if ( !m_properties[ nonUnicodePropId ].toCString().isEmpty() ) { + QCString encoding = m_properties[ nonUnicodePropId ].toCString(); + + mdb_set_encoding( m_mdb, (const char*) encoding ); + kdDebug() << "non-unicode encoding set to \"" + << encoding + << "\"" << endl; } - //supports setting source encoding - m_properties["source_database_has_nonunicode_encoding"] = QVariant( IS_JET3(m_mdb), 1 ); - + // Supports setting source encoding + m_properties[ isNonUnicodePropId ] = QVariant( IS_JET3(m_mdb), 1 ); + return true; } /*! Disconnect from the db backend */ bool MDBMigrate::drv_disconnect() -{ - mdb_close(m_mdb); +{ + mdb_close( m_mdb ); return true; } @@ -125,14 +137,15 @@ to the MdbTableDef - it doesn't load e.g. the column data. Remember to mdb_free_tabledef the table definition when it's finished with. - \return the table definition, or null if no matching table was found */ + \return the table definition, or null if no matching table was found +*/ MdbTableDef* MDBMigrate::getTableDef(const QString& tableName) { MdbTableDef *tableDef = 0; // Look through each entry in the catalogue ... for (unsigned int i = 0; i < m_mdb->num_catalog; i++) { - MdbCatalogEntry* dbObject = + MdbCatalogEntry* dbObject = (MdbCatalogEntry*)(g_ptr_array_index (m_mdb->catalog, i)); // ... for a table with the given name @@ -150,13 +163,9 @@ /* ************************************************************************** */ /*! Get the types and properties for each column. */ -bool MDBMigrate::drv_readTableSchema( - const QString& originalName, KexiDB::TableSchema& tableSchema) +bool MDBMigrate::drv_readTableSchema( const QString& originalName, + KexiDB::TableSchema& tableSchema ) { -//moved to migration lib: const QString tableID( KexiUtils::string2Identifier(table) ); -// m_table = new KexiDB::TableSchema(tableID); -// m_table->setCaption(table); - //! Get the column meta-data MdbTableDef *tableDef = getTableDef(originalName); if(!tableDef) { @@ -169,7 +178,7 @@ << tableDef->num_cols << endl; /*! Convert column data to Kexi TableSchema - Nice mix of terminology here, MDBTools has columns, Kexi has fields. */ + Nice mix of terminology here, MDBTools has columns, Kexi has fields. */ MdbColumn *col; for (unsigned int i = 0; i < tableDef->num_cols; i++) { col = (MdbColumn*) g_ptr_array_index(tableDef->columns, i); @@ -192,8 +201,10 @@ } getPrimaryKey(&tableSchema, tableDef); + //! Free the column meta-data - as soon as it doesn't seg fault. //mdb_free_tabledef(tableDef); + return true; } @@ -209,10 +220,12 @@ // Add non-system tables to the list for (unsigned int i = 0; i < m_mdb->num_catalog; i++) { - MdbCatalogEntry* dbObject = + MdbCatalogEntry* dbObject = (MdbCatalogEntry*)(g_ptr_array_index (m_mdb->catalog, i)); + if (dbObject->object_type == MDB_TABLE) { QString dbObjectName = QString::fromUtf8(dbObject->object_name); + if (!dbObjectName.startsWith("MSys")) { kdDebug() << "MDBMigrate::drv_tableNames: " << dbObjectName << endl; tableNames << dbObjectName; @@ -226,23 +239,23 @@ if(len == 0) { // Null ptr => null value return QVariant(); - } else if (type == MDB_SDATETIME ) { - return QDateTime::fromString(data, Qt::ISODate); } else { switch (type) { case MDB_TEXT: case MDB_MEMO: - return QVariant(QString::fromUtf8(data, len)); - case MDB_BOOL: + return QVariant( QString::fromUtf8(data, len) ); + case MDB_BOOL: //! @todo use &bool! case MDB_BYTE: - return QString::fromUtf8(data, len).toShort(); //! @todo use &bool! + return QString::fromUtf8(data, len).toShort(); + case MDB_SDATETIME: + return QDateTime::fromString(data, Qt::ISODate); case MDB_INT: case MDB_LONGINT: return QString::fromUtf8(data, len).toLongLong(); case MDB_FLOAT: return QString::fromUtf8(data, len).toFloat(); case MDB_DOUBLE: - case MDB_MONEY: //! @todo + case MDB_MONEY: //! @todo case MDB_NUMERIC: //! @todo return QString::fromUtf8(data, len).toDouble(); case MDB_OLE: @@ -254,8 +267,9 @@ } /*! Copy MDB table to KexiDB database */ -bool MDBMigrate::drv_copyTable(const QString& srcTable, - KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable) +bool MDBMigrate::drv_copyTable( const QString& srcTable, + KexiDB::Connection *destConn, + KexiDB::TableSchema* dstTable) { QString kdLoc = "MDBMigrate::drv_copyTable: "; MdbTableDef *tableDef = getTableDef(srcTable); @@ -271,8 +285,9 @@ mdb_read_columns(tableDef); // mdb_bind_column dies without this for (unsigned int i = 0; i < tableDef->num_cols; i++) { columnData[i] = (char*) g_malloc(MDB_BIND_SIZE); + // Columns are numbered from 1 - // and why arenĀ“t these unsigned ints? + // and why aren't these unsigned ints? mdb_bind_column(tableDef, i + 1, columnData[i], &columnDataLength[i]); } @@ -293,19 +308,16 @@ MdbColumn *col = (MdbColumn*) g_ptr_array_index(tableDef->columns, i); if (col->col_type == MDB_OLE && col->cur_value_len) { -// kdDebug() << kdLoc << "OLE!! @ " << i << endl; mdb_ole_read(m_mdb, col, columnData[i], MDB_BIND_SIZE); } //! @todo: How to import binary data? QVariant var = toQVariant(columnData[i], columnDataLength[i], col->col_type); -// kdDebug() << kdLoc << " col=" << i -// << " data=" << columnData[i] -// << " qvar=" << var.toString() << endl; vals << var; } - if (!destConn->insertRecord(*dstTable, vals)) { + + if ( !destConn->insertRecord( *dstTable, vals ) ) { ok = false; break; } @@ -316,7 +328,6 @@ if (++rows == KEXI_MIGRATION_MAX_ROWS_TO_IMPORT) break; #endif - } //! Deallocate (unbind) the DB columns arrays and column meta-data @@ -353,7 +364,7 @@ break; case MDB_MONEY: //! @todo temporary simplification - kexiType = KexiDB::Field::Double; + kexiType = KexiDB::Field::Double; break; case MDB_FLOAT: kexiType = KexiDB::Field::Float; @@ -375,7 +386,7 @@ break; //! @todo temporary simplification case MDB_NUMERIC: - kexiType = KexiDB::Field::Double; + kexiType = KexiDB::Field::Double; break; case MDB_REPID: // ? @@ -383,15 +394,16 @@ kexiType = KexiDB::Field::InvalidType; } - //Ask the user what to do with this field if we don't know what it is. + // If we don't know what it is, hope it's text. :o) if (kexiType == KexiDB::Field::InvalidType) { - return KexiDB::Field::LongText; //userType(); + return KexiDB::Field::LongText; } return kexiType; } -bool MDBMigrate::getPrimaryKey(KexiDB::TableSchema* table, MdbTableDef* tableDef) { +bool MDBMigrate::getPrimaryKey( KexiDB::TableSchema* table, + MdbTableDef* tableDef ) { QString kdLoc = "MDBMigrate::getPrimaryKey: "; MdbIndex *idx; @@ -406,8 +418,7 @@ for (unsigned int i = 0; i < tableDef->num_idxs; i++) { idx = (MdbIndex*) g_ptr_array_index (tableDef->indices, i); QString fldName = QString::fromUtf8(idx->name); -// kdDebug() << kdLoc << "got index " -// << fldName << "\"" << idx->name << endl; + if (!strcmp(idx->name, "PrimaryKey")) { idx = (MdbIndex*) g_ptr_array_index (tableDef->indices, i); foundIdx = true; @@ -432,7 +443,7 @@ for (unsigned int i = 0; i < idx->num_keys; i++) { key_col_num[i] = idx->key_col_num[i]; - kdDebug() << kdLoc << "key " << i + 1 + kdDebug() << kdLoc << "key " << i + 1 << " col " << key_col_num[i] << table->field(idx->key_col_num[i] - 1)->name() << endl; @@ -457,7 +468,7 @@ } bool MDBMigrate::drv_getTableSize(const QString& table, Q_ULLONG& size) { - //! Get the column meta-data + //! Get the column meta-data, which contains the table size MdbTableDef *tableDef = getTableDef(table); if(!tableDef) { kdDebug() << "MDBMigrate::drv_getTableDef: couldn't find table "