From e58ac2f2faa6619ecd7c95221ef0e65f83d73078 Mon Sep 17 00:00:00 2001 From: "Don C. Bigler" Date: Fri, 18 Dec 2020 19:41:00 -0500 Subject: [PATCH] Fix QTBUG-89612 --- src/plugins/sqldrivers/configure.json | 28 ++++++++++++++++++++--- src/plugins/sqldrivers/odbc/odbc.pro | 11 ++++++++- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 7 +++--- src/plugins/sqldrivers/odbc/qsql_odbc_p.h | 12 ++++++++-- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/plugins/sqldrivers/configure.json b/src/plugins/sqldrivers/configure.json index 28ccbeadcd..dd44bcdc65 100644 --- a/src/plugins/sqldrivers/configure.json +++ b/src/plugins/sqldrivers/configure.json @@ -128,8 +128,30 @@ "headers": [ "sql.h", "sqlext.h" ], "sources": [ { "libs": "-lodbc32", "condition": "config.win32" }, - { "libs": "-liodbc", "condition": "config.darwin" }, - { "libs": "-lodbc", "condition": "!config.win32 && !config.darwin" } + { "libs": "-lodbc", "condition": "!config.win32" } + ] + }, + "iodbc": { + "label": "IODBC", + "test": { + "head": [ + "#if defined(__APPLE__)", + "# include ", + "# include ", + "#else", + "# include ", + "# include ", + "#endif" + ], + "main": [ + "SQLHANDLE env;", + "SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);" + ], + "qmake": ["macx:QMAKE_CXXFLAGS += -F/Library/Frameworks"] + }, + "sources": [ + { "libs": "-F/Library/Frameworks -framework iODBC", "condition": "config.darwin" }, + { "libs": "-liodbc", "condition": "!config.win32 && !config.darwin" } ] }, "sqlite2": { @@ -183,7 +205,7 @@ }, "sql-odbc": { "label": "ODBC", - "condition": "features.datestring && libs.odbc", + "condition": "features.datestring && libs.odbc || libs.iodbc", "output": [ "privateFeature" ] }, "sql-psql": { diff --git a/src/plugins/sqldrivers/odbc/odbc.pro b/src/plugins/sqldrivers/odbc/odbc.pro index 17844f27d2..905f2c490d 100644 --- a/src/plugins/sqldrivers/odbc/odbc.pro +++ b/src/plugins/sqldrivers/odbc/odbc.pro @@ -3,10 +3,19 @@ TARGET = qsqlodbc HEADERS += $$PWD/qsql_odbc_p.h SOURCES += $$PWD/qsql_odbc.cpp $$PWD/main.cpp -QMAKE_USE += odbc unix: DEFINES += UNICODE OTHER_FILES += odbc.json PLUGIN_CLASS_NAME = QODBCDriverPlugin include(../qsqldriverbase.pri) + +defined(QMAKE_LIBS_ODBC, var) { + QMAKE_USE += odbc +} else { + macx { + DEFINES += Q_IODBC_MACOS_FRAMEWORK + QMAKE_CXXFLAGS += -F/Library/Frameworks + } + QMAKE_USE += iodbc +} diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 88f1c74028..57d62ecd8c 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -1583,10 +1583,10 @@ bool QODBCResult::exec() if (*ind != SQL_NULL_DATA) *ind = str.length() * sizeof(SQLTCHAR); int strSize = str.length() * sizeof(SQLTCHAR); + const QVarLengthArray a(toSQLTCHAR(str)); + ba = QByteArray((const char *)a.constData(), a.size() * sizeof(SQLTCHAR)); if (bindValueType(i) & QSql::Out) { - const QVarLengthArray a(toSQLTCHAR(str)); - ba = QByteArray((const char *)a.constData(), a.size() * sizeof(SQLTCHAR)); r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1599,7 +1599,6 @@ bool QODBCResult::exec() ind); break; } - ba = QByteArray ((const char *)toSQLTCHAR(str).constData(), str.size()*sizeof(SQLTCHAR)); r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1968,7 +1967,7 @@ bool QODBCDriver::open(const QString & db, r = SQLDriverConnect(d->hDbc, NULL, toSQLTCHAR(connQStr).data(), - (SQLSMALLINT)connQStr.length(), + SQL_NTS, connOut.data(), 1024, &cb, diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc_p.h b/src/plugins/sqldrivers/odbc/qsql_odbc_p.h index ccd0206f38..cf2b2b4233 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc_p.h +++ b/src/plugins/sqldrivers/odbc/qsql_odbc_p.h @@ -71,12 +71,20 @@ // workaround for Borland to make sure that SQLBIGINT is defined # define _MSC_VER 900 #endif -#include +#ifdef Q_IODBC_MACOS_FRAMEWORK +# include +#else +# include +#endif #if defined(Q_CC_BOR) # undef _MSC_VER #endif -#include +#ifdef Q_IODBC_MACOS_FRAMEWORK +# include +#else +# include +#endif QT_BEGIN_NAMESPACE -- 2.21.1 (Apple Git-122.3)