From e7c740280267a26c2c8bcc942d5c94187f24db05 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 3 Aug 2024 11:09:18 +0200 Subject: [PATCH] SQL/ODBC: Fix calling SQLGetData() for old drivers Some old drivers don't return SQL_NO_DATA when all data was fetched which resulted in an infinite loop. The previous check does not work when we receive chunked data and the driver returns fewer bytes than the maximum buffer size. Therefore simply check for SQL_SUCCESS since according the msdn docs, SQL_SUCCESS_WITH_INFO must be returned when there is more data to fetch. This also avoids an additional call to SQLGetData() here. Pick-to: 6.7 6.5 Fixes: QTBUG-119753 Change-Id: I42ed194f3955a650e63615615fe82d785f324228 Reviewed-by: Thiago Macieira --- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 868b6a89d35..57d4bc4d374 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -437,16 +437,15 @@ static QVariant getStringDataImpl(SQLHANDLE hStmt, SQLUSMALLINT column, qsizetyp // if SQL_SUCCESS_WITH_INFO is returned, indicating that // more data can be fetched, the length indicator does NOT // contain the number of bytes returned - it contains the - // total number of bytes that CAN be fetched + // total number of bytes that were transferred to our buffer const qsizetype rSize = (r == SQL_SUCCESS_WITH_INFO) ? buf.size() : qsizetype(lengthIndicator / sizeof(CT)); fieldVal += fromSQLTCHAR, sizeof(CT)>(buf, rSize); - // lengthIndicator does not contain the termination character - if (lengthIndicator < SQLLEN((buf.size() - 1) * sizeof(CT))) { - // workaround for Drivermanagers that don't return SQL_NO_DATA + // when we got SQL_SUCCESS_WITH_INFO then there is more data to fetch, + // otherwise we are done + if (r == SQL_SUCCESS) break; - } } else if (r == SQL_NO_DATA) { break; } else {