Skip to content
Snippets Groups Projects
Commit 219c02d1 authored by Jarosław Staniek's avatar Jarosław Staniek
Browse files

Add KDbConnection::drv_getTableNames for low level list of table names, make...

Add KDbConnection::drv_getTableNames for low level list of table names, make tableNames() skip names with non-existing physical tables

Summary:
- KDbTestUtils: add convenience APIs for connecting and using db, support connection options, use it in parser test
- Add KDbConnection::drv_getTableNames for low level list of table names, make tableNames() skip names with non-existing physical tables
- This change is backward compatible since metadata without physical table is not usable anyway.

CCBUG:392112
FIXED-IN:3.2.0

+ Add autotest for handling missing physical tables

Test Plan: Run ctest

Reviewers: piggz

Tags: #kdb

Differential Revision: https://phabricator.kde.org/D11547
parent 26203c29
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ ecm_add_tests(
ConnectionTest.cpp
DriverTest.cpp
ExpressionsTest.cpp
MissingTableTest.cpp
QuerySchemaTest.cpp
KDbTest.cpp
......@@ -49,6 +50,8 @@ ecm_add_tests(
kdbtestutils
)
target_compile_definitions(MissingTableTest PRIVATE -DFILES_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
if(NOT WIN32) #TODO enable for Windows when headers_test.sh is ported e.g. to python
add_subdirectory(headers)
endif()
......
/* This file is part of the KDE project
Copyright (C) 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
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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 library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <KDbTestUtils.h>
#include <KDbConnectionData>
#include <KDbConnectionOptions>
class MissingTableTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
//! Tests if the list of tables skips name for which physical table is missing.
//! The missingTableTest.kexi file has "persons" table deleted.
void testListTables();
void cleanupTestCase();
void cleanup();
private:
//! Opens database needed for tests
bool openDatabase(const QString &path);
KDbTestUtils m_utils;
};
void MissingTableTest::initTestCase()
{
}
void MissingTableTest::init()
{
QString dir(QFile::decodeName(FILES_DATA_DIR));
QVERIFY(openDatabase(dir + "/missingTableTest.kexi"));
}
bool MissingTableTest::openDatabase(const QString &path)
{
KDbConnectionOptions options;
options.setReadOnly(true);
return m_utils.testConnectAndUse(path, options);
}
void MissingTableTest::testListTables()
{
const bool alsoSystemTables = true;
bool ok;
QStringList foundTableNames = m_utils.connection->tableNames(alsoSystemTables, &ok);
QVERIFY(ok);
std::sort(foundTableNames.begin(), foundTableNames.end());
const QStringList expectedTables(
{ "cars", "kexi__db", "kexi__fields", "kexi__objectdata", "kexi__objects" });
QCOMPARE(foundTableNames, expectedTables);
}
void MissingTableTest::cleanup()
{
QVERIFY(m_utils.testDisconnect());
}
void MissingTableTest::cleanupTestCase()
{
}
QTEST_GUILESS_MAIN(MissingTableTest)
#include "MissingTableTest.moc"
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment