src/sql/drivers/odbc/qsql_odbc.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   170 {
   170 {
   171     SQLINTEGER nativeCode_ = 0;
   171     SQLINTEGER nativeCode_ = 0;
   172     SQLSMALLINT msgLen = 0;
   172     SQLSMALLINT msgLen = 0;
   173     SQLRETURN r = SQL_NO_DATA;
   173     SQLRETURN r = SQL_NO_DATA;
   174     SQLTCHAR state_[SQL_SQLSTATE_SIZE+1];
   174     SQLTCHAR state_[SQL_SQLSTATE_SIZE+1];
   175     SQLTCHAR description_[SQL_MAX_MESSAGE_LENGTH];
   175     QVarLengthArray<SQLTCHAR> description_(SQL_MAX_MESSAGE_LENGTH);
   176     QString result;
   176     QString result;
   177     int i = 1;
   177     int i = 1;
   178 
   178 
   179     description_[0] = 0;
   179     description_[0] = 0;
       
   180     r = SQLGetDiagRec(handleType,
       
   181                       handle,
       
   182                       i,
       
   183                       state_,
       
   184                       &nativeCode_,
       
   185                       0,
       
   186                       NULL,
       
   187                       &msgLen);
       
   188     if(r == SQL_NO_DATA)
       
   189         return QString();
       
   190     description_.resize(msgLen+1);
   180     do {
   191     do {
   181         r = SQLGetDiagRec(handleType,
   192         r = SQLGetDiagRec(handleType,
   182                             handle,
   193                             handle,
   183                             i,
   194                             i,
   184                             (SQLTCHAR*)state_,
   195                             state_,
   185                             &nativeCode_,
   196                             &nativeCode_,
   186                             (SQLTCHAR*)description_,
   197                             description_.data(),
   187                             SQL_MAX_MESSAGE_LENGTH, /* in bytes, not in characters */
   198                             description_.size(),
   188                             &msgLen);
   199                             &msgLen);
   189         if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
   200         if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
   190             if (nativeCode)
   201             if (nativeCode)
   191                 *nativeCode = nativeCode_;
   202                 *nativeCode = nativeCode_;
   192             QString tmpstore;
   203             QString tmpstore;
   193 #ifdef UNICODE
   204 #ifdef UNICODE
   194             tmpstore = QString((const QChar*)description_, msgLen);
   205             tmpstore = QString((const QChar*)description_.data(), msgLen);
   195 #else
   206 #else
   196             tmpstore = QString::fromLocal8Bit((const char*)description_, msgLen);
   207             tmpstore = QString::fromLocal8Bit((const char*)description_.data(), msgLen);
   197 #endif
   208 #endif
   198             if(result != tmpstore) {
   209             if(result != tmpstore) {
   199                 if(!result.isEmpty())
   210                 if(!result.isEmpty())
   200                     result += QLatin1Char(' ');
   211                     result += QLatin1Char(' ');
   201                 result += tmpstore;
   212                 result += tmpstore;