summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/odbc/qsql_odbc.cpp
diff options
context:
space:
mode:
authorMaximilian Hrabowski <maximilian.hrabowski@clausmark.com>2014-10-11 13:44:28 +0200
committerMark Brand <mabrand@mabrand.nl>2014-12-30 23:55:51 +0100
commita44749855e381a6f856b7b89ecd42aadcc2797bf (patch)
treee4dccb8cbbda5875881c2a5c7fb75aaa2ab690da /src/sql/drivers/odbc/qsql_odbc.cpp
parent190f64aab3fc8bb8e325bf48326c7b09d62b6419 (diff)
QODBC: fix converted string values empty SQLServer 2012
SQL Server 2012 Native Client (version 11.0.2100.60) or later introduced a change in the behavior of the SQLGetData method when converted string values are involved. In older version a (sometimes wrong) size was returned. Now always SQL_NO_TOTAL is returned which signals to read as much data as available. SQL_NO_TOTAL was handled like SQL_NULL_DATA in the code before which indicates a NULL value so the returned string was empty. See link for more info: http://msdn.microsoft.com/en-us/library/jj219209.aspx Change-Id: Ia0d2296caf593890b301ee1848d1bf3eb8d7b6fe Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'src/sql/drivers/odbc/qsql_odbc.cpp')
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index f95fb8868e..2b14809943 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -373,10 +373,20 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
colSize*sizeof(SQLTCHAR),
&lengthIndicator);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
- if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
+ if (lengthIndicator == SQL_NULL_DATA) {
fieldVal.clear();
break;
}
+ // starting with ODBC Native Client 2012, SQL_NO_TOTAL is returned
+ // instead of the length (which sometimes was wrong in older versions)
+ // see link for more info: http://msdn.microsoft.com/en-us/library/jj219209.aspx
+ // if length indicator equals SQL_NO_TOTAL, indicating that
+ // more data can be fetched, but size not known, collect data
+ // and fetch next block
+ if (lengthIndicator == SQL_NO_TOTAL) {
+ fieldVal += fromSQLTCHAR(buf, colSize);
+ continue;
+ }
// 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