summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2009-09-01 03:08:02 (GMT)
committerBill King <bill.king@nokia.com>2009-09-10 01:31:01 (GMT)
commitb19372c11549bc1f88b3e59fa94745645503b8e6 (patch)
treef8b442df253461b545046f5f3829ba51413a4da5 /src/sql
parenta77cc371917f7cda40e823b530693d38b85e666b (diff)
downloadQt-b19372c11549bc1f88b3e59fa94745645503b8e6.zip
Qt-b19372c11549bc1f88b3e59fa94745645503b8e6.tar.gz
Qt-b19372c11549bc1f88b3e59fa94745645503b8e6.tar.bz2
Fixes determination of end of odbc string on deficient driver
Ported this fix backwards from 4.6 to 4.5 Adds some cleanups (using QVarLengthArray), and reverting to the initial and correct calculation (when the driver doesn't deem fit to return SQL_NO_DATA).
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index ae522ee..a5c713d 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -314,12 +314,12 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
colSize *= 2; // a tiny bit faster, since it saves a SQLGetData() call
}
}
- char* buf = new char[colSize];
+ QVarLengthArray<char> buf(colSize);
while (true) {
r = SQLGetData(hStmt,
column+1,
unicode ? SQL_C_WCHAR : SQL_C_CHAR,
- (SQLPOINTER)buf,
+ (SQLPOINTER)buf.data(),
colSize,
&lengthIndicator);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
@@ -334,11 +334,12 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
// colSize-1: remove 0 termination when there is more data to fetch
int rSize = (r == SQL_SUCCESS_WITH_INFO) ? (unicode ? colSize-2 : colSize-1) : lengthIndicator;
if (unicode) {
- fieldVal += QString((QChar*) buf, rSize / 2);
+ fieldVal += QString((const QChar*) buf.constData(), rSize / 2);
} else {
- fieldVal += QString::fromAscii(buf, rSize);
+ fieldVal += QString::fromAscii(buf.constData(), rSize);
}
- if (lengthIndicator - fieldVal.size() <= 0) {
+ memset(buf.data(), 0, colSize);
+ if (lengthIndicator < colSize) {
// workaround for Drivermanagers that don't return SQL_NO_DATA
break;
}
@@ -350,7 +351,6 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
break;
}
}
- delete[] buf;
return fieldVal;
}