src/sql/drivers/odbc/qsql_odbc.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
--- a/src/sql/drivers/odbc/qsql_odbc.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/sql/drivers/odbc/qsql_odbc.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -172,28 +172,39 @@
     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())