summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/odbc
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-01 03:15:31 (GMT)
commit28635d8aeefbd0aa807f333769a0ab9fea9324b0 (patch)
treea2096ef480d96176b7d669e27a8458cbc7a1ee97 /src/sql/drivers/odbc
parentd80748df828b92f376ca779ab83776f3c9f53ce1 (diff)
downloadQt-28635d8aeefbd0aa807f333769a0ab9fea9324b0.zip
Qt-28635d8aeefbd0aa807f333769a0ab9fea9324b0.tar.gz
Qt-28635d8aeefbd0aa807f333769a0ab9fea9324b0.tar.bz2
Fixes determination of end of odbc string on deficient driver
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/drivers/odbc')
-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 742d596..2692c96 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -323,12 +323,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) {
@@ -343,11 +343,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;
}
@@ -359,7 +360,6 @@ static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool uni
break;
}
}
- delete[] buf;
return fieldVal;
}