[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kexi] /: Skip table name if physical table is non-existing, use the new tableNames API in migration
From:       Jaroslaw Staniek <null () kde ! org>
Date:       2018-06-05 22:32:33
Message-ID: E1fQKVF-0005dG-N8 () code ! kde ! org
[Download RAW message or body]

Git commit 83a672c348ca9d263e9739bb3ee5566ca8d5d702 by Jaroslaw Staniek.
Committed on 05/06/2018 at 22:32.
Pushed by staniek into branch 'master'.

Skip table name if physical table is non-existing, use the new tableNames API in \
migration

Summary:
BUG:392112
FIXED-IN:3.2.0

Note: functionality of migration is not affected, it's just the code cleanup thanks \
to the new API.

Test Plan: Open kdb.git/autotests/data/missingTableTest.kexi, it should not list \
persons table anymore.

Reviewers: piggz

Tags: #kexi

Differential Revision: https://phabricator.kde.org/D11549

M  +1    -1    CMakeLists.txt
M  +37   -11   src/core/kexiproject.cpp
M  +3    -15   src/migration/KexiSqlMigrate.cpp
M  +0    -3    src/migration/KexiSqlMigrate.h
M  +0    -1    src/migration/mysql/mysqlmigrate.cpp
M  +0    -1    src/migration/postgresql/PostgresqlMigrate.cpp

https://commits.kde.org/kexi/83a672c348ca9d263e9739bb3ee5566ca8d5d702

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d10d4beba..6c5a015db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -147,7 +147,7 @@ set(KEXI_EXAMPLES_INSTALL_DIR \
${SHARE_INSTALL_PREFIX}/${KEXI_BASE_PATH}/examples  ############################
 ###########################
 
-set(KEXI_FRAMEWORKS_MIN_VERSION 3.1.0)
+set(KEXI_FRAMEWORKS_MIN_VERSION 3.1.90)
 
 ##
 ## Test for KDb
diff --git a/src/core/kexiproject.cpp b/src/core/kexiproject.cpp
index f813c3aa0..944d58495 100644
--- a/src/core/kexiproject.cpp
+++ b/src/core/kexiproject.cpp
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
-   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2018 Jarosław Staniek <staniek@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -793,6 +793,7 @@ bool KexiProject::retrieveItems()
     int recentTypeId = -1000;
     QString pluginId;
     KexiPart::ItemDict *dict = 0;
+    QSet<QString> tableNamesSet;
     for (cursor->moveFirst(); !cursor->eof(); cursor->moveNext()) {
         bool ok;
         const int typeId = cursor->value(3).toInt(&ok);
@@ -802,8 +803,9 @@ bool KexiProject::retrieveItems()
             continue;
         }
         if (recentTypeId == typeId) {
-            if (pluginId.isEmpty()) // still the same unknown plugin ID
+            if (pluginId.isEmpty()) { // still the same unknown plugin ID
                 continue;
+            }
         }
         else {
             // a new type ID: create another plugin items dict if it's an ID for a \
known type @@ -813,20 +815,44 @@ bool KexiProject::retrieveItems()
                 continue;
             dict = new KexiPart::ItemDict();
             d->itemDicts.insert(pluginId, dict);
+            if (typeId == KDb::TableObjectType) {
+                // Starting to load table names: initialize.
+                // This list since 3.2 does not contain names without physical \
tables so we can +                // catch these cases below.
+                const QStringList tableNames(d->connection->tableNames(false \
/*public*/, &ok)); +                if (!ok) {
+                    m_result = KDbResult(ERR_OBJECT_NOT_FOUND, xi18n("Could not load \
list of tables.")); +                    qDeleteAll(d->itemDicts);
+                    return false;
+                }
+                for (const QString &name : tableNames) {
+                    tableNamesSet.insert(name.toLower());
+                }
+            }
         }
         const int ident = cursor->value(0).toInt(&ok);
         const QString objName(cursor->value(1).toString());
-        if (ok && (ident > 0) && !d->connection->isInternalTableSchema(objName)
-                && KDb::isIdentifier(objName))
+        if (!ok || ident <= 0 || !KDb::isIdentifier(objName))
         {
-            KexiPart::Item *it = new KexiPart::Item();
-            it->setIdentifier(ident);
-            it->setPluginId(pluginId);
-            it->setName(objName);
-            it->setCaption(cursor->value(2).toString());
-            dict->insert(it->identifier(), it);
+            continue; // invalid ID or invalid name
+        }
+        if (typeId == KDb::TableObjectType) {
+            if (d->connection->isInternalTableSchema(objName)) {
+                qInfo() << "table" << objName << "id=" << ident << "is internal, \
skipping"; +                continue;
+            }
+            if (!tableNamesSet.contains(objName.toLower())) {
+                qInfo() << "table" << objName << "id=" << ident
+                        << "does not correspondent with physical table";
+                continue;
+            }
         }
-  //qDebug() << "ITEM ADDED == "<<objName <<" id="<<ident;
+        KexiPart::Item *it = new KexiPart::Item();
+        it->setIdentifier(ident);
+        it->setPluginId(pluginId);
+        it->setName(objName);
+        it->setCaption(cursor->value(2).toString());
+        dict->insert(it->identifier(), it);
     }
 
     d->connection->deleteCursor(cursor);
diff --git a/src/migration/KexiSqlMigrate.cpp b/src/migration/KexiSqlMigrate.cpp
index 117922915..749cc8182 100644
--- a/src/migration/KexiSqlMigrate.cpp
+++ b/src/migration/KexiSqlMigrate.cpp
@@ -86,21 +86,9 @@ bool KexiSqlMigrate::drv_readTableSchema(
 
 bool KexiSqlMigrate::drv_tableNames(QStringList *tableNames)
 {
-    QSharedPointer<KDbSqlResult> result = \
                sourceConnection()->prepareSql(m_tableNamesSql);
-    if (!result || result->fieldsCount() < 1) {
-        return false;
-    }
-    Q_FOREVER {
-        QSharedPointer<KDbSqlRecord> record = result->fetchRecord();
-        if (!record) {
-            if (result->lastResult().isError()) {
-                return false;
-            }
-            break;
-        }
-        tableNames->append(record->stringValue(0));
-    }
-    return true;
+    bool ok;
+    *tableNames = sourceConnection()->drv_getTableNames(&ok);
+    return ok;
 }
 
 tristate KexiSqlMigrate::drv_queryStringListFromSql(
diff --git a/src/migration/KexiSqlMigrate.h b/src/migration/KexiSqlMigrate.h
index f15b23834..1cda1c23e 100644
--- a/src/migration/KexiSqlMigrate.h
+++ b/src/migration/KexiSqlMigrate.h
@@ -76,9 +76,6 @@ protected:
     QSharedPointer<KDbSqlResult> drv_readFromTable(const QString & tableName) \
Q_DECL_OVERRIDE;  
     const QString m_kdbDriverId;
-
-    //! Used by drv_tableNames, should be filled in constructor of a subclass
-    KDbEscapedString m_tableNamesSql;
 };
 
 #endif
diff --git a/src/migration/mysql/mysqlmigrate.cpp \
b/src/migration/mysql/mysqlmigrate.cpp index 411c87f69..7edadd983 100644
--- a/src/migration/mysql/mysqlmigrate.cpp
+++ b/src/migration/mysql/mysqlmigrate.cpp
@@ -29,7 +29,6 @@ KEXI_PLUGIN_FACTORY(MysqlMigrate, "keximigrate_mysql.json")
 MysqlMigrate::MysqlMigrate(QObject *parent, const QVariantList& args)
     : KexiSqlMigrate(QLatin1String("org.kde.kdb.mysql"), parent, args)
 {
-    m_tableNamesSql = KDbEscapedString("SHOW TABLES");
 }
 
 MysqlMigrate::~MysqlMigrate()
diff --git a/src/migration/postgresql/PostgresqlMigrate.cpp \
b/src/migration/postgresql/PostgresqlMigrate.cpp index be2a12f29..6e24e6e87 100644
--- a/src/migration/postgresql/PostgresqlMigrate.cpp
+++ b/src/migration/postgresql/PostgresqlMigrate.cpp
@@ -29,7 +29,6 @@ KEXI_PLUGIN_FACTORY(PostgresqlMigrate, \
"keximigrate_postgresql.json")  PostgresqlMigrate::PostgresqlMigrate(QObject *parent, \
                const QVariantList& args)
     : KexiSqlMigrate(QLatin1String("org.kde.kdb.postgresql"), parent, args)
 {
-    m_tableNamesSql = KDbEscapedString("SELECT table_name FROM \
information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN \
('pg_catalog', 'information_schema')");  }
 
 PostgresqlMigrate::~PostgresqlMigrate()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic