Ignore:
Timestamp:
Aug 2, 2010, 9:27:30 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/sql/drivers/odbc/qsql_odbc.cpp

    r651 r769  
    6767# undef UNICODE
    6868# define SQLTCHAR SQLCHAR
    69 # define SQL_C_WCHAR SQL_C_CHAR
     69# define SQL_C_TCHAR SQL_C_CHAR
    7070#endif
    7171
     
    7979#endif
    8080
    81 
    8281static const int COLNAMESIZE = 256;
    8382//Map Qt parameter types to ODBC types
    8483static const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT };
    8584
     85inline static QString fromSQLTCHAR(const QVarLengthArray<SQLTCHAR>& input, int size=-1)
     86{
     87    QString result;
     88
     89    int realsize = qMin(size, input.size());
     90    if(realsize > 0 && input[realsize-1] == 0)
     91        realsize--;
     92    switch(sizeof(SQLTCHAR)) {
     93        case 1:
     94            result=QString::fromUtf8((const char *)input.constData(), realsize);
     95            break;
     96        case 2:
     97            result=QString::fromUtf16((const ushort *)input.constData(), realsize);
     98            break;
     99        case 4:
     100            result=QString::fromUcs4((const uint *)input.constData(), realsize);
     101            break;
     102        default:
     103            qCritical() << "sizeof(SQLTCHAR) is " << sizeof(SQLTCHAR) << "Don't know how to handle this";
     104    }
     105    return result;
     106}
     107
     108inline static QVarLengthArray<SQLTCHAR> toSQLTCHAR(const QString &input)
     109{
     110    QVarLengthArray<SQLTCHAR> result;
     111    result.resize(input.size());
     112    switch(sizeof(SQLTCHAR)) {
     113        case 1:
     114            memcpy(result.data(), input.toUtf8().data(), input.size());
     115            break;
     116        case 2:
     117            memcpy(result.data(), input.unicode(), input.size() * 2);
     118            break;
     119        case 4:
     120            memcpy(result.data(), input.toUcs4().data(), input.size() * 4);
     121            break;
     122        default:
     123            qCritical() << "sizeof(SQLTCHAR) is " << sizeof(SQLTCHAR) << "Don't know how to handle this";
     124    }
     125    result.append(0); // make sure it's null terminated, doesn't matter if it already is, it does if it isn't.
     126    return result;
     127}
     128
    86129class QODBCDriverPrivate
    87130{
     
    89132    enum DefaultCase{Lower, Mixed, Upper, Sensitive};
    90133    QODBCDriverPrivate()
    91     : hEnv(0), hDbc(0), useSchema(false), disconnectCount(0), isMySqlServer(false),
    92            isMSSqlServer(false), hasSQLFetchScroll(true), hasMultiResultSets(false),
    93            isQuoteInitialized(false), quote(QLatin1Char('"'))
     134    : hEnv(0), hDbc(0), unicode(false), useSchema(false), disconnectCount(0), isMySqlServer(false),
     135           isMSSqlServer(false), isFreeTDSDriver(false), hasSQLFetchScroll(true),
     136           hasMultiResultSets(false), isQuoteInitialized(false), quote(QLatin1Char('"'))
    94137    {
    95         unicode = false;
    96138    }
    97139
     
    99141    SQLHANDLE hDbc;
    100142
    101     uint unicode :1;
    102     uint useSchema :1;
     143    bool unicode;
     144    bool useSchema;
    103145    int disconnectCount;
    104146    bool isMySqlServer;
    105147    bool isMSSqlServer;
     148    bool isFreeTDSDriver;
    106149    bool hasSQLFetchScroll;
    107150    bool hasMultiResultSets;
     
    130173    : hStmt(0), useSchema(false), hasSQLFetchScroll(true), driverPrivate(dpp), userForwardOnly(false)
    131174    {
    132         unicode = false;
     175        unicode = dpp->unicode;
     176        useSchema = dpp->useSchema;
     177        disconnectCount = dpp->disconnectCount;
     178        hasSQLFetchScroll = dpp->hasSQLFetchScroll;
    133179    }
    134180
     
    140186    SQLHANDLE hStmt;
    141187
    142     uint unicode :1;
    143     uint useSchema :1;
     188    bool unicode;
     189    bool useSchema;
    144190
    145191    QSqlRecord rInf;
     
    178224
    179225    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);
    191226    do {
     227        r = SQLGetDiagRec(handleType,
     228                          handle,
     229                          i,
     230                          state_,
     231                          &nativeCode_,
     232                          0,
     233                          NULL,
     234                          &msgLen);
     235        if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && msgLen > 0)
     236            description_.resize(msgLen+1);
    192237        r = SQLGetDiagRec(handleType,
    193238                            handle,
     
    203248            QString tmpstore;
    204249#ifdef UNICODE
    205             tmpstore = QString((const QChar*)description_.data(), msgLen);
     250            tmpstore = fromSQLTCHAR(description_, msgLen);
    206251#else
    207             tmpstore = QString::fromLocal8Bit((const char*)description_.data(), msgLen);
     252            tmpstore = QString::fromUtf8((const char*)description_.constData(), msgLen);
    208253#endif
    209254            if(result != tmpstore) {
     
    224269    return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->dpEnv()) + QLatin1Char(' ')
    225270             + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->dpDbc()) + QLatin1Char(' ')
    226              + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode));
     271             + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)).simplified();
    227272}
    228273
     
    230275{
    231276    return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ')
    232              + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode));
     277             + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode)).simplified();
    233278}
    234279
     
    308353    case SQL_CHAR:
    309354    case SQL_VARCHAR:
     355#if (ODBCVER >= 0x0350)
    310356    case SQL_GUID:
     357#endif
    311358    case SQL_LONGVARCHAR:
    312359        type = QVariant::String;
     
    332379    } else {
    333380        colSize++; // make sure there is room for more than the 0 termination
    334         if (unicode) {
    335             colSize *= 2; // a tiny bit faster, since it saves a SQLGetData() call
    336         }
    337     }
    338     QVarLengthArray<char> buf(colSize);
    339     while (true) {
     381    }
     382    if(unicode) {
    340383        r = SQLGetData(hStmt,
    341384                        column+1,
    342                         unicode ? SQL_C_WCHAR : SQL_C_CHAR,
    343                         (SQLPOINTER)buf.data(),
    344                         colSize,
     385                        SQL_C_TCHAR,
     386                        NULL,
     387                        0,
    345388                        &lengthIndicator);
    346         if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
    347             if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
     389        if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && lengthIndicator > 0)
     390            colSize = lengthIndicator/sizeof(SQLTCHAR) + 1;
     391        QVarLengthArray<SQLTCHAR> buf(colSize);
     392        memset(buf.data(), 0, colSize*sizeof(SQLTCHAR));
     393        while (true) {
     394            r = SQLGetData(hStmt,
     395                            column+1,
     396                            SQL_C_TCHAR,
     397                            (SQLPOINTER)buf.data(),
     398                            colSize*sizeof(SQLTCHAR),
     399                            &lengthIndicator);
     400            if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
     401                if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
     402                    fieldVal.clear();
     403                    break;
     404                }
     405                // if SQL_SUCCESS_WITH_INFO is returned, indicating that
     406                // more data can be fetched, the length indicator does NOT
     407                // contain the number of bytes returned - it contains the
     408                // total number of bytes that CAN be fetched
     409                // colSize-1: remove 0 termination when there is more data to fetch
     410                int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator/sizeof(SQLTCHAR);
     411                    fieldVal += fromSQLTCHAR(buf, rSize);
     412                if (lengthIndicator < (unsigned int)colSize*sizeof(SQLTCHAR)) {
     413                    // workaround for Drivermanagers that don't return SQL_NO_DATA
     414                    break;
     415                }
     416            } else if (r == SQL_NO_DATA) {
     417                break;
     418            } else {
     419                qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')';
    348420                fieldVal.clear();
    349421                break;
    350422            }
    351             // if SQL_SUCCESS_WITH_INFO is returned, indicating that
    352             // more data can be fetched, the length indicator does NOT
    353             // contain the number of bytes returned - it contains the
    354             // total number of bytes that CAN be fetched
    355             // colSize-1: remove 0 termination when there is more data to fetch
    356             int rSize = (r == SQL_SUCCESS_WITH_INFO) ? (unicode ? colSize-2 : colSize-1) : lengthIndicator;
    357             if (unicode) {
    358                 fieldVal += QString((const QChar*) buf.constData(), rSize / 2);
     423        }
     424    } else {
     425        r = SQLGetData(hStmt,
     426                        column+1,
     427                        SQL_C_CHAR,
     428                        NULL,
     429                        0,
     430                        &lengthIndicator);
     431        if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && lengthIndicator > 0)
     432            colSize = lengthIndicator + 1;
     433        QVarLengthArray<SQLCHAR> buf(colSize);
     434        while (true) {
     435            r = SQLGetData(hStmt,
     436                            column+1,
     437                            SQL_C_CHAR,
     438                            (SQLPOINTER)buf.data(),
     439                            colSize,
     440                            &lengthIndicator);
     441            if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
     442                if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
     443                    fieldVal.clear();
     444                    break;
     445                }
     446                // if SQL_SUCCESS_WITH_INFO is returned, indicating that
     447                // more data can be fetched, the length indicator does NOT
     448                // contain the number of bytes returned - it contains the
     449                // total number of bytes that CAN be fetched
     450                // colSize-1: remove 0 termination when there is more data to fetch
     451                int rSize = (r == SQL_SUCCESS_WITH_INFO) ? colSize : lengthIndicator;
     452                    fieldVal += QString::fromUtf8((const char *)buf.constData(), rSize);
     453                if (lengthIndicator < (unsigned int)colSize) {
     454                    // workaround for Drivermanagers that don't return SQL_NO_DATA
     455                    break;
     456                }
     457            } else if (r == SQL_NO_DATA) {
     458                break;
    359459            } else {
    360                 fieldVal += QString::fromAscii(buf.constData(), rSize);
    361             }
    362             memset(buf.data(), 0, colSize);
    363             if (lengthIndicator < colSize) {
    364                 // workaround for Drivermanagers that don't return SQL_NO_DATA
     460                qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')';
     461                fieldVal.clear();
    365462                break;
    366463            }
    367         } else if (r == SQL_NO_DATA) {
    368             break;
    369         } else {
    370             qWarning() << "qGetStringData: Error while fetching data (" << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ')';
    371             fieldVal.clear();
    372             break;
    373464        }
    374465    }
     
    387478    SQLRETURN r = SQL_ERROR;
    388479
    389     SQLTCHAR colName[COLNAMESIZE];
     480    QVarLengthArray<SQLTCHAR> colName(COLNAMESIZE);
     481
    390482    r = SQLDescribeCol(hStmt,
    391483                       column + 1,
    392                        colName,
     484                       colName.data(),
    393485                       COLNAMESIZE,
    394486                       &colNameLen,
     
    523615    SQLSMALLINT nullable;
    524616    SQLRETURN r = SQL_ERROR;
    525     SQLTCHAR colName[COLNAMESIZE];
     617    QVarLengthArray<SQLTCHAR> colName(COLNAMESIZE);
    526618    r = SQLDescribeCol(p->hStmt,
    527619                        i+1,
    528                         colName,
     620                        colName.data(),
    529621                        (SQLSMALLINT)COLNAMESIZE,
    530622                        &colNameLen,
     
    552644
    553645#ifdef UNICODE
    554     QString qColName((const QChar*)colName, colNameLen);
     646    QString qColName(fromSQLTCHAR(colName, colNameLen));
    555647#else
    556     QString qColName = QString::fromLocal8Bit((const char*)colName);
     648    QString qColName = QString::fromUtf8((const char *)colName.constData());
    557649#endif
    558650    // nullable can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
     
    582674        return SQL_OV_ODBC3;
    583675#endif
     676    if (connOpts.contains(QLatin1String("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC2"), Qt::CaseInsensitive))
     677        return SQL_OV_ODBC2;
     678#ifdef _IODBCUNIX_H
     679    return SQL_OV_ODBC3;
     680#else
    584681    return SQL_OV_ODBC2;
     682#endif
    585683}
    586684
     
    588686{
    589687    if (!isQuoteInitialized) {
    590         char driverResponse[4];
     688        SQLTCHAR driverResponse[4];
    591689        SQLSMALLINT length;
    592690        int r = SQLGetInfo(hDbc,
     
    595693                sizeof(driverResponse),
    596694                &length);
    597         if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
     695        if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
     696#ifdef UNICODE
     697            quote = QChar(driverResponse[0]);
     698#else
    598699            quote = QLatin1Char(driverResponse[0]);
    599         } else {
     700#endif
     701        else
    600702            quote = QLatin1Char('"');
    601         }
    602703        isQuoteInitialized = true;
    603704    }
     
    643744            r = SQLSetConnectAttr(hDbc, SQL_ATTR_CURRENT_CATALOG,
    644745#ifdef UNICODE
    645                                     (SQLWCHAR*) val.unicode(),
     746                                    toSQLTCHAR(val).data(),
    646747#else
    647                                     (SQLCHAR*) val.toLatin1().constData(),
    648 #endif
    649                                     SQL_NTS);
     748                                    (SQLCHAR*) val.toUtf8().data(),
     749#endif
     750                                    val.length()*sizeof(SQLTCHAR));
    650751        } else if (opt.toUpper() == QLatin1String("SQL_ATTR_METADATA_ID")) {
    651752            if (val.toUpper() == QLatin1String("SQL_TRUE")) {
     
    665766            r = SQLSetConnectAttr(hDbc, SQL_ATTR_TRACEFILE,
    666767#ifdef UNICODE
    667                                     (SQLWCHAR*) val.unicode(),
     768                                    toSQLTCHAR(val).data(),
    668769#else
    669                                     (SQLCHAR*) val.toLatin1().constData(),
    670 #endif
    671                                     SQL_NTS);
     770                                    (SQLCHAR*) val.toUtf8().data(),
     771#endif
     772                                    val.length()*sizeof(SQLTCHAR));
    672773        } else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACE")) {
    673774            if (val.toUpper() == QLatin1String("SQL_OPT_TRACE_OFF")) {
     
    815916{
    816917    d = new QODBCPrivate(p);
    817     d->unicode = p->unicode;
    818     d->useSchema = p->useSchema;
    819     d->disconnectCount = p->disconnectCount;
    820     d->hasSQLFetchScroll = p->hasSQLFetchScroll;
    821918}
    822919
     
    881978#ifdef UNICODE
    882979    r = SQLExecDirect(d->hStmt,
    883                        (SQLWCHAR*) query.unicode(),
     980                       toSQLTCHAR(query).data(),
    884981                       (SQLINTEGER) query.length());
    885982#else
    886     QByteArray query8 = query.toLocal8Bit();
     983    QByteArray query8 = query.toUtf8();
    887984    r = SQLExecDirect(d->hStmt,
    888                        (SQLCHAR*) query8.constData(),
     985                       (SQLCHAR*) query8.data(),
    889986                       (SQLINTEGER) query8.length());
    890987#endif
     
    12321329#ifdef UNICODE
    12331330    r = SQLPrepare(d->hStmt,
    1234                     (SQLWCHAR*) query.unicode(),
     1331                    toSQLTCHAR(query).data(),
    12351332                    (SQLINTEGER) query.length());
    12361333#else
    1237     QByteArray query8 = query.toLocal8Bit();
     1334    QByteArray query8 = query.toUtf8();
    12381335    r = SQLPrepare(d->hStmt,
    1239                     (SQLCHAR*) query8.constData(),
     1336                    (SQLCHAR*) query8.data(),
    12401337                    (SQLINTEGER) query8.length());
    12411338#endif
     
    14361533                if (d->unicode) {
    14371534                    QString str = val.toString();
    1438                     str.utf16();
    14391535                    if (*ind != SQL_NULL_DATA)
    1440                         *ind = str.length() * sizeof(QChar);
    1441                     int strSize = str.length() * sizeof(QChar);
     1536                        *ind = str.length() * sizeof(SQLTCHAR);
     1537                    int strSize = str.length() * sizeof(SQLTCHAR);
    14421538
    14431539                    if (bindValueType(i) & QSql::Out) {
    1444                         QByteArray ba((char*)str.constData(), str.capacity() * sizeof(QChar));
     1540                        QVarLengthArray<SQLTCHAR> ba(toSQLTCHAR(str));
     1541                        ba.reserve(str.capacity());
    14451542                        r = SQLBindParameter(d->hStmt,
    14461543                                            i + 1,
    14471544                                            qParamType[(QFlag)(bindValueType(i)) & QSql::InOut],
    1448                                             SQL_C_WCHAR,
     1545                                            SQL_C_TCHAR,
    14491546                                            strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR,
    14501547                                            0, // god knows... don't change this!
     
    14531550                                            ba.size(),
    14541551                                            ind);
    1455                         tmpStorage.append(ba);
     1552                        tmpStorage.append(QByteArray((const char *)ba.constData(), ba.size()*sizeof(SQLTCHAR)));
    14561553                        break;
    14571554                    }
    1458 
     1555                    QByteArray strba((const char *)toSQLTCHAR(str).constData(), str.size()*sizeof(SQLTCHAR));
    14591556                    r = SQLBindParameter(d->hStmt,
    14601557                                          i + 1,
    14611558                                          qParamType[(QFlag)(bindValueType(i)) & QSql::InOut],
    1462                                           SQL_C_WCHAR,
     1559                                          SQL_C_TCHAR,
    14631560                                          strSize > 254 ? SQL_WLONGVARCHAR : SQL_WVARCHAR,
    14641561                                          strSize,
    14651562                                          0,
    1466                                           (void *)str.constData(),
    1467                                           strSize,
     1563                                          (SQLPOINTER)strba.constData(),
     1564                                          strba.size(),
    14681565                                          ind);
     1566                    tmpStorage.append(strba);
    14691567                    break;
    14701568                }
     
    14721570#endif
    14731571                {
    1474                     QByteArray str = val.toString().toAscii();
     1572                    QByteArray str = val.toString().toUtf8();
    14751573                    if (*ind != SQL_NULL_DATA)
    14761574                        *ind = str.length();
     
    15731671            case QVariant::String:
    15741672                if (d->unicode) {
    1575                     if (bindValueType(i) & QSql::Out)
    1576                         values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData());
     1673                    if (bindValueType(i) & QSql::Out) {
     1674                        QByteArray first = tmpStorage.takeFirst();
     1675                        QVarLengthArray<SQLTCHAR> array;
     1676                        array.append((SQLTCHAR *)first.constData(), first.size());
     1677                        values[i] = fromSQLTCHAR(array, first.size()/sizeof(SQLTCHAR*));
     1678                    }
    15771679                    break;
    15781680                }
    15791681                // fall through
    15801682            default: {
    1581                 QByteArray ba = tmpStorage.takeFirst();
    15821683                if (bindValueType(i) & QSql::Out)
    1583                     values[i] = QString::fromAscii(ba.constData());
     1684                    values[i] = tmpStorage.takeFirst();
    15841685                break; }
    15851686        }
     
    17901891
    17911892    SQLSMALLINT cb;
    1792     SQLTCHAR connOut[1024];
     1893    QVarLengthArray<SQLTCHAR> connOut(1024);
     1894    memset(connOut.data(), 0, connOut.size() * sizeof(SQLTCHAR));
    17931895    r = SQLDriverConnect(d->hDbc,
    17941896                          NULL,
    17951897#ifdef UNICODE
    1796                           (SQLWCHAR*)connQStr.unicode(),
     1898                          toSQLTCHAR(connQStr).data(),
    17971899#else
    1798                           (SQLCHAR*)connQStr.toLatin1().constData(),
     1900                          (SQLCHAR*)connQStr.toUtf8().data(),
    17991901#endif
    18001902                          (SQLSMALLINT)connQStr.length(),
    1801                           connOut,
     1903                          connOut.data(),
    18021904                          1024,
    18031905                          &cb,
    1804                           SQL_DRIVER_NOPROMPT);
     1906                          /*SQL_DRIVER_NOPROMPT*/0);
     1907
    18051908    if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
    18061909        setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d));
     
    18871990    if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WCHAR)) {
    18881991        unicode = true;
     1992        return;
    18891993    }
    18901994
     
    18962000    if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WVARCHAR)) {
    18972001        unicode = true;
     2002        return;
    18982003    }
    18992004
     
    19052010    if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (fFunc & SQL_CVT_WLONGVARCHAR)) {
    19062011        unicode = true;
    1907     }
     2012        return;
     2013    }
     2014    SQLHANDLE hStmt;
     2015    r = SQLAllocHandle(SQL_HANDLE_STMT,
     2016                                  hDbc,
     2017                                  &hStmt);
     2018
     2019    r = SQLExecDirect(hStmt, toSQLTCHAR(QLatin1String("select 'test'")).data(), SQL_NTS);
     2020    if(r == SQL_SUCCESS) {
     2021        r = SQLFetch(hStmt);
     2022        if(r == SQL_SUCCESS) {
     2023            QVarLengthArray<SQLWCHAR> buffer(10);
     2024            r = SQLGetData(hStmt, 1, SQL_C_WCHAR, buffer.data(), buffer.size() * sizeof(SQLWCHAR), NULL);
     2025            if(r == SQL_SUCCESS && fromSQLTCHAR(buffer) == QLatin1String("test")) {
     2026                unicode = true;
     2027            }
     2028        }
     2029    }
     2030    r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
    19082031}
    19092032
     
    19782101{
    19792102    SQLRETURN   r;
    1980     char serverString[200];
     2103    QVarLengthArray<SQLTCHAR> serverString(200);
    19812104    SQLSMALLINT t;
     2105    memset(serverString.data(), 0, serverString.size() * sizeof(SQLTCHAR));
    19822106
    19832107    r = SQLGetInfo(hDbc,
    19842108                   SQL_DBMS_NAME,
    1985                    serverString,
    1986                    sizeof(serverString),
     2109                   serverString.data(),
     2110                   serverString.size() * sizeof(SQLTCHAR),
    19872111                   &t);
    19882112    if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
    19892113        QString serverType;
    19902114#ifdef UNICODE
    1991         serverType = QString(reinterpret_cast<const QChar*>(serverString), t/sizeof(QChar));
     2115        serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR));
    19922116#else
    1993         serverType = QString::fromLocal8Bit(serverString, t);
     2117        serverType = QString::fromUtf8((const char *)serverString.constData(), t);
    19942118#endif
    19952119        isMySqlServer = serverType.contains(QLatin1String("mysql"), Qt::CaseInsensitive);
    19962120        isMSSqlServer = serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive);
     2121    }
     2122    r = SQLGetInfo(hDbc,
     2123                   SQL_DRIVER_NAME,
     2124                   serverString.data(),
     2125                   serverString.size() * sizeof(SQLTCHAR),
     2126                   &t);
     2127    if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
     2128        QString serverType;
     2129#ifdef UNICODE
     2130        serverType = fromSQLTCHAR(serverString, t/sizeof(SQLTCHAR));
     2131#else
     2132        serverType = QString::fromUtf8((const char *)serverString.constData(), t);
     2133#endif
     2134        isFreeTDSDriver = serverType.contains(QLatin1String("tdsodbc"), Qt::CaseInsensitive);
     2135        unicode = isFreeTDSDriver == false;
    19972136    }
    19982137}
     
    20102149void QODBCDriverPrivate::checkHasMultiResults()
    20112150{
    2012     char driverResponse[4];
     2151    QVarLengthArray<SQLTCHAR> driverResponse(2);
    20132152    SQLSMALLINT length;
    20142153    SQLRETURN r = SQLGetInfo(hDbc,
    20152154                             SQL_MULT_RESULT_SETS,
    2016                              driverResponse,
    2017                              sizeof(driverResponse),
     2155                             driverResponse.data(),
     2156                             driverResponse.size() * sizeof(SQLTCHAR),
    20182157                             &length);
    20192158    if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
    20202159#ifdef UNICODE
    2021         hasMultiResultSets = QString(reinterpret_cast<const QChar*>(driverResponse), length/sizeof(QChar)).startsWith(QLatin1Char('Y'));
     2160        hasMultiResultSets = fromSQLTCHAR(driverResponse, length/sizeof(SQLTCHAR)).startsWith(QLatin1Char('Y'));
    20222161#else
    2023         hasMultiResultSets = QString::fromLocal8Bit(driverResponse, length).startsWith(QLatin1Char('Y'));
     2162        hasMultiResultSets = QString::fromUtf8((const char *)driverResponse.constData(), length).startsWith(QLatin1Char('Y'));
    20242163#endif
    20252164}
     
    21352274                   0,
    21362275#ifdef UNICODE
    2137                    (SQLWCHAR*)joinedTableTypeString.unicode(),
     2276                   toSQLTCHAR(joinedTableTypeString).data(),
    21382277#else
    2139                    (SQLCHAR*)joinedTableTypeString.toLatin1().constData(),
     2278                   (SQLCHAR*)joinedTableTypeString.toUtf8().data(),
    21402279#endif
    21412280                   joinedTableTypeString.length() /* characters, not bytes */);
     
    21502289    else
    21512290        r = SQLFetch(hStmt);
     2291
     2292    if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) {
     2293        qWarning() << "QODBCDriver::tables failed to retrieve table/view list: (" << r << "," << qWarnODBCHandle(SQL_HANDLE_STMT, hStmt) << ")";
     2294        return QStringList();
     2295    }
    21522296
    21532297    while (r == SQL_SUCCESS) {
     
    22092353    r = SQLPrimaryKeys(hStmt,
    22102354#ifdef UNICODE
    2211                         catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),
     2355                        catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
    22122356#else
    2213                         catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toLatin1().constData(),
     2357                        catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
    22142358#endif
    22152359                        catalog.length(),
    22162360#ifdef UNICODE
    2217                         schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),
     2361                        schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
    22182362#else
    2219                         schema.length() == 0 ? NULL : (SQLCHAR*)schema.toLatin1().constData(),
     2363                        schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
    22202364#endif
    22212365                        schema.length(),
    22222366#ifdef UNICODE
    2223                         (SQLWCHAR*)table.unicode(),
     2367                        toSQLTCHAR(table).data(),
    22242368#else
    2225                         (SQLCHAR*)table.toLatin1().constData(),
     2369                        (SQLCHAR*)table.toUtf8().data(),
    22262370#endif
    22272371                        table.length() /* in characters, not in bytes */);
     
    22342378                        SQL_BEST_ROWID,
    22352379#ifdef UNICODE
    2236                         catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),
     2380                        catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
    22372381#else
    2238                         catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toLatin1().constData(),
     2382                        catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
    22392383#endif
    22402384                        catalog.length(),
    22412385#ifdef UNICODE
    2242                         schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),
     2386                        schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
    22432387#else
    2244                         schema.length() == 0 ? NULL : (SQLCHAR*)schema.toLatin1().constData(),
     2388                        schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
    22452389#endif
    22462390                        schema.length(),
    22472391#ifdef UNICODE
    2248                         (SQLWCHAR*)table.unicode(),
     2392                        toSQLTCHAR(table).data(),
    22492393#else
    2250                         (SQLCHAR*)table.toLatin1().constData(),
     2394                        (SQLCHAR*)table.toUtf8().data(),
    22512395#endif
    22522396                        table.length(),
     
    23342478    r =  SQLColumns(hStmt,
    23352479#ifdef UNICODE
    2336                      catalog.length() == 0 ? NULL : (SQLWCHAR*)catalog.unicode(),
     2480                     catalog.length() == 0 ? NULL : toSQLTCHAR(catalog).data(),
    23372481#else
    2338                      catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toLatin1().constData(),
     2482                     catalog.length() == 0 ? NULL : (SQLCHAR*)catalog.toUtf8().data(),
    23392483#endif
    23402484                     catalog.length(),
    23412485#ifdef UNICODE
    2342                      schema.length() == 0 ? NULL : (SQLWCHAR*)schema.unicode(),
     2486                     schema.length() == 0 ? NULL : toSQLTCHAR(schema).data(),
    23432487#else
    2344                      schema.length() == 0 ? NULL : (SQLCHAR*)schema.toLatin1().constData(),
     2488                     schema.length() == 0 ? NULL : (SQLCHAR*)schema.toUtf8().data(),
    23452489#endif
    23462490                     schema.length(),
    23472491#ifdef UNICODE
    2348                      (SQLWCHAR*)table.unicode(),
     2492                     toSQLTCHAR(table).data(),
    23492493#else
    2350                      (SQLCHAR*)table.toLatin1().constData(),
     2494                     (SQLCHAR*)table.toUtf8().data(),
    23512495#endif
    23522496                     table.length(),
  • trunk/src/sql/drivers/odbc/qsql_odbc.h

    r651 r769  
    7474#if defined(Q_CC_BOR)
    7575#  undef _MSC_VER
    76 #endif
    77 
    78 #ifndef Q_ODBC_VERSION_2
    79 #include <sqlucode.h>
    8076#endif
    8177
Note: See TracChangeset for help on using the changeset viewer.