Changeset View
Standalone View
src/KDbConnection.cpp
Show First 20 Lines • Show All 1000 Lines • ▼ Show 20 Line(s) | 982 | { | |||
---|---|---|---|---|---|
1001 | if (!success) { | 1001 | if (!success) { | ||
1002 | m_result.prependMessage(tr("Could not retrieve list of object names.")); | 1002 | m_result.prependMessage(tr("Could not retrieve list of object names.")); | ||
1003 | } | 1003 | } | ||
1004 | return list; | 1004 | return list; | ||
1005 | } | 1005 | } | ||
1006 | 1006 | | |||
1007 | QStringList KDbConnection::tableNames(bool alsoSystemTables, bool* ok) | 1007 | QStringList KDbConnection::tableNames(bool alsoSystemTables, bool* ok) | ||
1008 | { | 1008 | { | ||
1009 | QStringList result; | ||||
1009 | bool success; | 1010 | bool success; | ||
1010 | QStringList list = objectNames(KDb::TableObjectType, &success); | 1011 | if (!ok) { | ||
1011 | if (ok) { | 1012 | ok = &success; | ||
1012 | *ok = success; | | |||
1013 | } | 1013 | } | ||
1014 | if (!success) { | 1014 | QStringList list = objectNames(KDb::TableObjectType, ok); | ||
1015 | if (!*ok) { | ||||
1015 | m_result.prependMessage(tr("Could not retrieve list of table names.")); | 1016 | m_result.prependMessage(tr("Could not retrieve list of table names.")); | ||
1017 | return QStringList(); | ||||
1016 | } | 1018 | } | ||
1017 | if (alsoSystemTables && success) { | 1019 | if (alsoSystemTables) { | ||
1018 | list += kdbSystemTableNames(); | 1020 | list += kdbSystemTableNames(); | ||
1019 | } | 1021 | } | ||
1020 | return list; | 1022 | const QStringList physicalTableNames = drv_getTableNames(ok); | ||
1023 | if (!*ok) { | ||||
1024 | m_result.prependMessage(tr("Could not retrieve list of physical table names.")); | ||||
1025 | return QStringList(); | ||||
piggz: should we also set ok to false to indicate a failure? or, how else to indicate to the caller… | |||||
This is good question for other reason. So far I assume (even documented it) that drv_getTableNames returns false only if this approach to enumerating tables is not supported by the driver. But you're right in that it would be future proof to add bool*ok to drv_getTableNames... so we can see difference between 'unsupported' and 'failure'. It that makes sense I will rework. staniek: This is good question for other reason. So far I assume (even documented it) that… | |||||
that is another case I didnt think of, but yes, could be done. I was thinking about setting the bool* ok to false that is passed into this function to tell the caller of an error. piggz: that is another case I didnt think of, but yes, could be done. I was thinking about setting… | |||||
Did both things: staniek: Did both things:
https://phabricator.kde.org/D11547?id=30112 | |||||
1026 | } | ||||
1027 | QSet<QString> physicalTableNamesSet; | ||||
1028 | for (const QString &name : physicalTableNames) { | ||||
1029 | physicalTableNamesSet.insert(name.toLower()); | ||||
1030 | } | ||||
1031 | for (const QString &name : list) { | ||||
what about using QSet::intersect() ? piggz: what about using QSet::intersect() ?
something like
QSet<QString> physical = QSet::fromList(std… | |||||
Initially I tried to use QSet::intersect but we have to call toLower() on each name. Until Qt 6 has more algorithms I am not fan of converting to stl and back. staniek: Initially I tried to use QSet::intersect but we have to call toLower() on each name. Until Qt 6… | |||||
piggz: ok | |||||
1032 | if (physicalTableNamesSet.contains(name.toLower())) { | ||||
1033 | result += name; | ||||
1034 | } | ||||
1035 | } | ||||
1036 | return result; | ||||
1021 | } | 1037 | } | ||
1022 | 1038 | | |||
1023 | tristate KDbConnection::containsTable(const QString &tableName) | 1039 | tristate KDbConnection::containsTable(const QString &tableName) | ||
1024 | { | 1040 | { | ||
1025 | return drv_containsTable(tableName); | 1041 | return drv_containsTable(tableName); | ||
1026 | } | 1042 | } | ||
1027 | 1043 | | |||
1028 | QStringList KDbConnection::kdbSystemTableNames() | 1044 | QStringList KDbConnection::kdbSystemTableNames() | ||
▲ Show 20 Lines • Show All 792 Lines • ▼ Show 20 Line(s) | 1834 | { | |||
1821 | if (!qs) { | 1837 | if (!qs) { | ||
1822 | m_result = KDbResult(ERR_OBJECT_NOT_FOUND, | 1838 | m_result = KDbResult(ERR_OBJECT_NOT_FOUND, | ||
1823 | tr("Query \"%1\" does not exist.").arg(queryName)); | 1839 | tr("Query \"%1\" does not exist.").arg(queryName)); | ||
1824 | return false; | 1840 | return false; | ||
1825 | } | 1841 | } | ||
1826 | return dropQuery(qs); | 1842 | return dropQuery(qs); | ||
1827 | } | 1843 | } | ||
1828 | 1844 | | |||
1845 | QStringList KDbConnection::drv_getTableNames(bool *ok) | ||||
1846 | { | ||||
1847 | Q_ASSERT(ok); | ||||
1848 | QStringList tableNames; | ||||
1849 | const KDbEscapedString sql(d->driver->behavior()->GET_TABLE_NAMES_SQL); | ||||
1850 | if (sql.isEmpty()) { | ||||
1851 | *ok = false; | ||||
1852 | return QStringList(); | ||||
1853 | } | ||||
1854 | QSharedPointer<KDbSqlResult> result = prepareSql(sql); | ||||
1855 | if (!result) { | ||||
1856 | *ok = false; | ||||
1857 | return QStringList(); | ||||
1858 | } | ||||
1859 | Q_FOREVER { | ||||
1860 | QSharedPointer<KDbSqlRecord> record = result->fetchRecord(); | ||||
1861 | if (!record) { | ||||
1862 | if (result->lastResult().isError()) { | ||||
1863 | *ok = false; | ||||
1864 | return QStringList(); | ||||
1865 | } | ||||
1866 | break; | ||||
1867 | } | ||||
1868 | tableNames.append(record->stringValue(0)); | ||||
1869 | } | ||||
1870 | *ok = true; | ||||
1871 | return tableNames; | ||||
1872 | } | ||||
1873 | | ||||
1829 | bool KDbConnection::drv_createTable(const KDbTableSchema& tableSchema) | 1874 | bool KDbConnection::drv_createTable(const KDbTableSchema& tableSchema) | ||
1830 | { | 1875 | { | ||
1831 | const KDbNativeStatementBuilder builder(this, KDb::DriverEscaping); | 1876 | const KDbNativeStatementBuilder builder(this, KDb::DriverEscaping); | ||
1832 | KDbEscapedString sql; | 1877 | KDbEscapedString sql; | ||
1833 | if (!builder.generateCreateTableStatement(&sql,tableSchema)) { | 1878 | if (!builder.generateCreateTableStatement(&sql,tableSchema)) { | ||
1834 | return false; | 1879 | return false; | ||
1835 | } | 1880 | } | ||
1836 | //kdbDebug() << "******** " << sql; | 1881 | //kdbDebug() << "******** " << sql; | ||
▲ Show 20 Lines • Show All 1666 Lines • Show Last 20 Lines |
should we also set ok to false to indicate a failure? or, how else to indicate to the caller an error occurred, and not just that there are no tables?