From 05ec29f76c69f8f6efd24d725d59fc5cf6b4b2ce Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 15 Oct 2022 20:49:25 +0200 Subject: [PATCH] SQL/Tests: fix tst_qsqldatabase::caseSensivity() for MySQL on linux MySQL has a different default setting for case sensitive table names on linux and windows which makes the test fail on linux but work on windows when using the database with the default settings. Read out the respecitive setting so the test will pass every time. Change-Id: I8651858d47652022ddc4b6386a6153cf70c6fed6 Reviewed-by: Volker Hilsheimer --- .../kernel/qsqldatabase/tst_qsqldatabase.cpp | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index 69f65ad9ef..77ee1583fb 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -1243,21 +1243,21 @@ void tst_QSqlDatabase::caseSensivity() } QSqlRecord rec = db.record(qTableName("qtest", __FILE__, db, driverQuotedCaseSensitive(db))); - QVERIFY((int)rec.count() > 0); + QVERIFY(rec.count() > 0); if (!cs) { - rec = db.record(qTableName("QTEST", __FILE__, db, false).toUpper()); - QVERIFY((int)rec.count() > 0); - rec = db.record(qTableName("qTesT", __FILE__, db, false)); - QVERIFY((int)rec.count() > 0); + rec = db.record(qTableName("QTEST", __FILE__, db, false).toUpper()); + QVERIFY(rec.count() > 0); + rec = db.record(qTableName("qTesT", __FILE__, db, false)); + QVERIFY(rec.count() > 0); } rec = db.primaryIndex(qTableName("qtest", __FILE__, db, driverQuotedCaseSensitive(db))); - QVERIFY((int)rec.count() > 0); + QVERIFY(rec.count() > 0); if (!cs) { - rec = db.primaryIndex(qTableName("QTEST", __FILE__, db, false).toUpper()); - QVERIFY((int)rec.count() > 0); - rec = db.primaryIndex(qTableName("qTesT", __FILE__, db, false)); - QVERIFY((int)rec.count() > 0); + rec = db.primaryIndex(qTableName("QTEST", __FILE__, db, false).toUpper()); + QVERIFY(rec.count() > 0); + rec = db.primaryIndex(qTableName("qTesT", __FILE__, db, false)); + QVERIFY(rec.count() > 0); } // Explicit test for case sensitive table creation without quoting @@ -1269,6 +1269,13 @@ void tst_QSqlDatabase::caseSensivity() QVERIFY_SQL(qry, exec("SELECT * FROM " + noQuotesTable)); QVERIFY_SQL(qry, next()); QCOMPARE(qry.value(0).toInt(), 1); + // QMYSQLDriver::record() is using a mysql function instead of a query, so quoting + // will not help when the table names are not stored lowercase. + if (dbType == QSqlDriver::MySqlServer) { + QVERIFY_SQL(qry, exec("SHOW GLOBAL VARIABLES LIKE 'lower_case_table_names'")); + QVERIFY_SQL(qry, next()); + cs = qry.value(1).toInt() != 0; + } rec = db.record(cs ? noQuotesTable.toLower() : noQuotesTable); QVERIFY(rec.count() > 0); }