summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorBill King <bking@trolltech.com>2009-12-15 03:09:12 (GMT)
committerBill King <bking@trolltech.com>2009-12-15 03:09:12 (GMT)
commit82ec0a6c26c683dedd20fb6dd3923dce98c3f7e3 (patch)
tree47e095977dc9ae6e20bedff0b1e8f963ede741e5 /src/sql
parent504d6d4ac0d782c1fbca1f2dc1e8425dac773113 (diff)
downloadQt-82ec0a6c26c683dedd20fb6dd3923dce98c3f7e3.zip
Qt-82ec0a6c26c683dedd20fb6dd3923dce98c3f7e3.tar.gz
Qt-82ec0a6c26c683dedd20fb6dd3923dce98c3f7e3.tar.bz2
(ODBC) Fixes segfault when error string is larger than 256 chars.
SqlServer can throw custom error messages (via RaiseError) that can be up to 8000 chars long. Fixed this with a pre-query as to the length of the error string, then allocating enough space to retrieve the whole error string at once. Task-number: QTBUG-6618 Reviewed-by: Derick Hawcroft
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/drivers/odbc/qsql_odbc.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp
index e686873..fdf0c2c 100644
--- a/src/sql/drivers/odbc/qsql_odbc.cpp
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp
@@ -172,28 +172,39 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode
SQLSMALLINT msgLen = 0;
SQLRETURN r = SQL_NO_DATA;
SQLTCHAR state_[SQL_SQLSTATE_SIZE+1];
- SQLTCHAR description_[SQL_MAX_MESSAGE_LENGTH];
+ QVarLengthArray<SQLTCHAR> description_(SQL_MAX_MESSAGE_LENGTH);
QString result;
int i = 1;
description_[0] = 0;
+ r = SQLGetDiagRec(handleType,
+ handle,
+ i,
+ state_,
+ &nativeCode_,
+ 0,
+ NULL,
+ &msgLen);
+ if(r == SQL_NO_DATA)
+ return QString();
+ description_.resize(msgLen+1);
do {
r = SQLGetDiagRec(handleType,
handle,
i,
- (SQLTCHAR*)state_,
+ state_,
&nativeCode_,
- (SQLTCHAR*)description_,
- SQL_MAX_MESSAGE_LENGTH, /* in bytes, not in characters */
+ description_.data(),
+ description_.size(),
&msgLen);
if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
if (nativeCode)
*nativeCode = nativeCode_;
QString tmpstore;
#ifdef UNICODE
- tmpstore = QString((const QChar*)description_, msgLen);
+ tmpstore = QString((const QChar*)description_.data(), msgLen);
#else
- tmpstore = QString::fromLocal8Bit((const char*)description_, msgLen);
+ tmpstore = QString::fromLocal8Bit((const char*)description_.data(), msgLen);
#endif
if(result != tmpstore) {
if(!result.isEmpty())