SQL/ODBC: add another check to detect unicode availability in driver
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Sun, 28 Apr 2024 18:48:02 +0000 (20:48 +0200)
committerThorsten Alteholz <debian@alteholz.de>
Sun, 28 Apr 2024 18:48:02 +0000 (20:48 +0200)
Origin: upstream, https://code.qt.io/cgit/qt/qtbase.git/commit/?id=f19320748d282b1e
Last-Update: 2023-06-30

Since ODBC does not have a direct way finding out if unicode is
supported by the underlying driver the ODBC plugin does some checks. As
a last resort a sql statement is executed which returns a string. But
even this may fail because the select statement has no FROM part which
is rejected by at least Oracle does not allow. Therefore add another
query which is correct for Oracle & DB2 as a workaround. The question
why the first three statements to check for unicode availability fail
is still open but can't be checked since I've no access to an oracle
database.

Gbp-Pq: Name sql_odbc_more_unicode_checks.diff

src/plugins/sqldrivers/odbc/qsql_odbc.cpp

index 6cac60d03d2a4ea932de08ef00e040abf98e6b91..5e1eefebdab3b1d5c9dd12bc1ec88a8dc1399e4a 100644 (file)
@@ -2111,7 +2111,18 @@ void QODBCDriverPrivate::checkUnicode()
                                   hDbc,
                                   &hStmt);
 
-    r = SQLExecDirect(hStmt, toSQLTCHAR(QLatin1String("select 'test'")).data(), SQL_NTS);
+    // for databases which do not return something useful in SQLGetInfo and are picky about a
+    // 'SELECT' statement without 'FROM' but support VALUE(foo) statement like e.g. DB2 or Oracle
+    const auto statements = {
+        QLatin1String("select 'test'"),
+        QLatin1String("values('test')"),
+        QLatin1String("select 'test' from dual"),
+    };
+    for (const auto &statement : statements) {
+        r = SQLExecDirect(hStmt, toSQLTCHAR(statement).data(), SQL_NTS);
+        if (r == SQL_SUCCESS)
+            break;
+    }
     if(r == SQL_SUCCESS) {
         r = SQLFetch(hStmt);
         if(r == SQL_SUCCESS) {