Changeset View
Changeset View
Standalone View
Standalone View
src/core/kexiproject.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> | 2 | Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> | ||
3 | Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> | 3 | Copyright (C) 2003-2018 Jarosław Staniek <staniek@kde.org> | ||
4 | 4 | | |||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
9 | 9 | | |||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 776 Lines • ▼ Show 20 Line(s) | 784 | { | |||
788 | if (!cursor) { | 788 | if (!cursor) { | ||
789 | m_result = d->connection->result(); | 789 | m_result = d->connection->result(); | ||
790 | return 0; | 790 | return 0; | ||
791 | } | 791 | } | ||
792 | 792 | | |||
793 | int recentTypeId = -1000; | 793 | int recentTypeId = -1000; | ||
794 | QString pluginId; | 794 | QString pluginId; | ||
795 | KexiPart::ItemDict *dict = 0; | 795 | KexiPart::ItemDict *dict = 0; | ||
796 | QSet<QString> tableNamesSet; | ||||
796 | for (cursor->moveFirst(); !cursor->eof(); cursor->moveNext()) { | 797 | for (cursor->moveFirst(); !cursor->eof(); cursor->moveNext()) { | ||
797 | bool ok; | 798 | bool ok; | ||
798 | const int typeId = cursor->value(3).toInt(&ok); | 799 | const int typeId = cursor->value(3).toInt(&ok); | ||
799 | if (!ok || typeId <= 0) { | 800 | if (!ok || typeId <= 0) { | ||
800 | qInfo() << "object of unknown type id" << cursor->value(3) << "id=" << cursor->value(0) | 801 | qInfo() << "object of unknown type id" << cursor->value(3) << "id=" << cursor->value(0) | ||
801 | << "name=" << cursor->value(1); | 802 | << "name=" << cursor->value(1); | ||
802 | continue; | 803 | continue; | ||
803 | } | 804 | } | ||
804 | if (recentTypeId == typeId) { | 805 | if (recentTypeId == typeId) { | ||
805 | if (pluginId.isEmpty()) // still the same unknown plugin ID | 806 | if (pluginId.isEmpty()) { // still the same unknown plugin ID | ||
806 | continue; | 807 | continue; | ||
807 | } | 808 | } | ||
809 | } | ||||
808 | else { | 810 | else { | ||
809 | // a new type ID: create another plugin items dict if it's an ID for a known type | 811 | // a new type ID: create another plugin items dict if it's an ID for a known type | ||
810 | recentTypeId = typeId; | 812 | recentTypeId = typeId; | ||
811 | pluginId = pluginIdForTypeId(typeId); | 813 | pluginId = pluginIdForTypeId(typeId); | ||
812 | if (pluginId.isEmpty()) | 814 | if (pluginId.isEmpty()) | ||
813 | continue; | 815 | continue; | ||
814 | dict = new KexiPart::ItemDict(); | 816 | dict = new KexiPart::ItemDict(); | ||
815 | d->itemDicts.insert(pluginId, dict); | 817 | d->itemDicts.insert(pluginId, dict); | ||
818 | if (typeId == KDb::TableObjectType) { | ||||
819 | // Starting to load table names: initialize. | ||||
820 | // This list since 3.2 does not contain names without physical tables so we can | ||||
821 | // catch these cases below. | ||||
822 | const QStringList tableNames(d->connection->tableNames(false /*public*/, &ok)); | ||||
823 | if (!ok) { | ||||
824 | m_result = KDbResult(ERR_OBJECT_NOT_FOUND, xi18n("Could not load list of tables.")); | ||||
825 | qDeleteAll(d->itemDicts); | ||||
826 | return false; | ||||
827 | } | ||||
828 | for (const QString &name : tableNames) { | ||||
829 | tableNamesSet.insert(name.toLower()); | ||||
830 | } | ||||
831 | } | ||||
816 | } | 832 | } | ||
817 | const int ident = cursor->value(0).toInt(&ok); | 833 | const int ident = cursor->value(0).toInt(&ok); | ||
818 | const QString objName(cursor->value(1).toString()); | 834 | const QString objName(cursor->value(1).toString()); | ||
819 | if (ok && (ident > 0) && !d->connection->isInternalTableSchema(objName) | 835 | if (!ok || ident <= 0 || !KDb::isIdentifier(objName)) | ||
820 | && KDb::isIdentifier(objName)) | | |||
821 | { | 836 | { | ||
837 | continue; // invalid ID or invalid name | ||||
838 | } | ||||
839 | if (typeId == KDb::TableObjectType) { | ||||
840 | if (d->connection->isInternalTableSchema(objName)) { | ||||
841 | qInfo() << "table" << objName << "id=" << ident << "is internal, skipping"; | ||||
842 | continue; | ||||
843 | } | ||||
844 | if (!tableNamesSet.contains(objName.toLower())) { | ||||
845 | qInfo() << "table" << objName << "id=" << ident | ||||
846 | << "does not correspondent with physical table"; | ||||
847 | continue; | ||||
848 | } | ||||
849 | } | ||||
822 | KexiPart::Item *it = new KexiPart::Item(); | 850 | KexiPart::Item *it = new KexiPart::Item(); | ||
823 | it->setIdentifier(ident); | 851 | it->setIdentifier(ident); | ||
824 | it->setPluginId(pluginId); | 852 | it->setPluginId(pluginId); | ||
825 | it->setName(objName); | 853 | it->setName(objName); | ||
826 | it->setCaption(cursor->value(2).toString()); | 854 | it->setCaption(cursor->value(2).toString()); | ||
827 | dict->insert(it->identifier(), it); | 855 | dict->insert(it->identifier(), it); | ||
828 | } | 856 | } | ||
829 | //qDebug() << "ITEM ADDED == "<<objName <<" id="<<ident; | | |||
830 | } | | |||
831 | 857 | | |||
832 | d->connection->deleteCursor(cursor); | 858 | d->connection->deleteCursor(cursor); | ||
833 | return true; | 859 | return true; | ||
834 | } | 860 | } | ||
835 | 861 | | |||
836 | int KexiProject::typeIdForPluginId(const QString &pluginId) const | 862 | int KexiProject::typeIdForPluginId(const QString &pluginId) const | ||
837 | { | 863 | { | ||
838 | return d->typeIds.value(pluginId, -1); | 864 | return d->typeIds.value(pluginId, -1); | ||
▲ Show 20 Lines • Show All 651 Lines • Show Last 20 Lines |