Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/sql/drivers/db2/qsql_db2.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtSql module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5050#include <qvarlengtharray.h>
    5151#include <qvector.h>
    52 
    53 #ifndef UNICODE
    54 #define UNICODE
    55 #endif
     52#include <QDebug>
    5653
    5754#if defined(Q_CC_BOR)
     
    6360#endif
    6461
     62#define UNICODE
     63
    6564#include <sqlcli1.h>
    6665
     
    8483{
    8584public:
    86     QDB2ResultPrivate(const QDB2DriverPrivate* d): dp(d), hStmt(0), precisionPolicy(QSql::HighPrecision)
     85    QDB2ResultPrivate(const QDB2DriverPrivate* d): dp(d), hStmt(0)
    8786    {}
    8887    ~QDB2ResultPrivate()
    8988    {
    90         for (int i = 0; i < valueCache.count(); ++i)
     89        emptyValueCache();
     90    }
     91    void clearValueCache()
     92    {
     93        for (int i = 0; i < valueCache.count(); ++i) {
    9194            delete valueCache[i];
     95            valueCache[i] = NULL;
     96        }
     97    }
     98    void emptyValueCache()
     99    {
     100        clearValueCache();
     101        valueCache.clear();
    92102    }
    93103
     
    96106    QSqlRecord recInf;
    97107    QVector<QVariant*> valueCache;
    98     QSql::NumericalPrecisionPolicy precisionPolicy;
    99108};
    100109
    101110static QString qFromTChar(SQLTCHAR* str)
    102111{
    103 #ifdef UNICODE
    104112    return QString::fromUtf16(str);
    105 #else
    106     return QString::fromLocal8Bit((const char*) str);
    107 #endif
    108113}
    109114
     
    112117static SQLTCHAR* qToTChar(const QString& str)
    113118{
    114 #ifdef UNICODE
    115119    return (SQLTCHAR*)str.utf16();
    116 #else
    117     return (unsigned char*) str.ascii();
    118 #endif
    119120}
    120121
     
    337338    while (true) {
    338339        r = SQLGetData(hStmt,
    339                         column+1,
    340 #ifdef UNICODE
     340                        column + 1,
    341341                        SQL_C_WCHAR,
    342 #else
    343                         SQL_C_CHAR,
    344 #endif
    345342                        (SQLPOINTER)buf,
    346343                        colSize * sizeof(SQLTCHAR),
     
    545542
    546543    d->recInf.clear();
    547     d->valueCache.clear();
     544    d->emptyValueCache();
    548545
    549546    if (!qMakeStatement(d, isForwardOnly()))
     
    569566    }
    570567    d->valueCache.resize(count);
     568    d->valueCache.fill(NULL);
    571569    setActive(true);
    572570    return true;
     
    580578
    581579    d->recInf.clear();
    582     d->valueCache.clear();
     580    d->emptyValueCache();
    583581
    584582    if (!qMakeStatement(d, isForwardOnly()))
     
    608606
    609607    d->recInf.clear();
    610     d->valueCache.clear();
     608    d->emptyValueCache();
    611609
    612610    if (!qMakeStatement(d, isForwardOnly(), false))
     
    729727                break; }
    730728            case QVariant::String:
    731 #ifdef UNICODE
    732729            {
    733730                QString str(values.at(i).toString());
     
    763760                break;
    764761            }
    765 #endif
    766             // fall through
    767762            default: {
    768763                QByteArray ba = values.at(i).toString().toAscii();
     
    812807    setActive(true);
    813808    d->valueCache.resize(count);
     809    d->valueCache.fill(NULL);
    814810
    815811    //get out parameters
     
    837833                break;
    838834            case QVariant::String:
    839 #ifdef UNICODE
    840835                if (bindValueType(i) & QSql::Out)
    841836                    values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData());
    842837                break;
    843 #endif
    844                 // fall through
    845838            default: {
    846839                values[i] = QString::fromAscii(tmpStorage.takeFirst().constData());
     
    859852    if (i == at())
    860853        return true;
    861     d->valueCache.fill(0);
     854    d->clearValueCache();
    862855    int actualIdx = i + 1;
    863856    if (actualIdx <= 0) {
     
    876869                            actualIdx);
    877870    }
    878     if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
     871    if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO && r != SQL_NO_DATA) {
    879872        setLastError(qMakeError(QCoreApplication::translate("QDB2Result",
    880873                                "Unable to fetch record %1").arg(i), QSqlError::StatementError, d));
    881874        return false;
    882875    }
     876    else if (r == SQL_NO_DATA)
     877        return false;
    883878    setAt(i);
    884879    return true;
     
    888883{
    889884    SQLRETURN r;
    890     d->valueCache.fill(0);
     885    d->clearValueCache();
    891886    r = SQLFetchScroll(d->hStmt,
    892887                       SQL_FETCH_NEXT,
     
    908903    if (isForwardOnly())
    909904        return fetchNext();
    910     d->valueCache.fill(0);
     905    d->clearValueCache();
    911906    SQLRETURN r;
    912907    r = SQLFetchScroll(d->hStmt,
     
    914909                       0);
    915910    if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
    916         setLastError(qMakeError(QCoreApplication::translate("QDB2Result", "Unable to fetch first"),
    917                                 QSqlError::StatementError, d));
     911        if(r!= SQL_NO_DATA)
     912            setLastError(qMakeError(QCoreApplication::translate("QDB2Result", "Unable to fetch first"),
     913                                    QSqlError::StatementError, d));
    918914        return false;
    919915    }
     
    924920bool QDB2Result::fetchLast()
    925921{
    926     d->valueCache.fill(0);
     922    d->clearValueCache();
    927923
    928924    int i = at();
     
    10301026        case QVariant::Double:
    10311027            {
    1032             QString value=qGetStringData(d->hStmt, field, info.length() + 1, isNull);
    1033             bool ok=false;
    1034             switch(d->precisionPolicy) {
     1028            switch(numericalPrecisionPolicy()) {
    10351029                case QSql::LowPrecisionInt32:
    1036                     v = new QVariant(value.toInt(&ok));
     1030                    v = new QVariant(qGetIntData(d->hStmt, field, isNull));
    10371031                    break;
    10381032                case QSql::LowPrecisionInt64:
    1039                     v = new QVariant(value.toLongLong(&ok));
     1033                    v = new QVariant(qGetBigIntData(d->hStmt, field, isNull));
    10401034                    break;
    10411035                case QSql::LowPrecisionDouble:
    1042                     v = new QVariant(value.toDouble(&ok));
     1036                    v = new QVariant(qGetDoubleData(d->hStmt, field, isNull));
    10431037                    break;
    10441038                case QSql::HighPrecision:
     
    10461040                    // length + 1 for the comma
    10471041                    v = new QVariant(qGetStringData(d->hStmt, field, info.length() + 1, isNull));
    1048                     ok = true;
    10491042                    break;
    10501043            }
    1051             if(!ok)
    1052                 v = new QVariant();
    10531044            break;
    10541045            }
     
    11021093    setAt(QSql::BeforeFirstRow);
    11031094    d->recInf.clear();
    1104     d->valueCache.clear();
     1095    d->emptyValueCache();
    11051096    setSelect(false);
    11061097
     
    11211112
    11221113    d->valueCache.resize(fieldCount);
     1114    d->valueCache.fill(NULL);
    11231115    setActive(true);
    11241116
     
    11331125        *static_cast<bool*>(data) = nextResult();
    11341126        break;
    1135     case QSqlResult::SetNumericalPrecision:
    1136         Q_ASSERT(data);
    1137         d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);
     1127    case QSqlResult::DetachFromResultSet:
     1128        if (d->hStmt)
     1129            SQLCloseCursor(d->hStmt);
    11381130        break;
    11391131    default:
     
    11681160}
    11691161
    1170 bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString&, int,
     1162bool QDB2Driver::open(const QString& db, const QString& user, const QString& password, const QString& host, int port,
    11711163                       const QString& connOpts)
    11721164{
     
    11911183        return false;
    11921184    }
     1185
     1186    QString protocol;
    11931187    // Set connection attributes
    11941188    const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts));
     
    12211215            v = val.toUInt();
    12221216            r = SQLSetConnectAttr(d->hDbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) v, 0);
    1223         } else {
     1217        } else if (opt.compare(QLatin1String("PROTOCOL"), Qt::CaseInsensitive) == 0) {
     1218                        protocol = tmp;
     1219        }
     1220        else {
    12241221            qWarning("QDB2Driver::open: Unknown connection attribute '%s'",
    12251222                      tmp.toLocal8Bit().constData());
     
    12301227    }
    12311228
     1229    if (protocol.isEmpty())
     1230        protocol = QLatin1String("PROTOCOL=TCPIP");
     1231
     1232    if (port < 0 )
     1233        port = 50000;
     1234
    12321235    QString connQStr;
    1233     connQStr = QLatin1String("DSN=") + db + QLatin1String(";UID=") + user + QLatin1String(";PWD=")
    1234                + password;
     1236    connQStr =  protocol + QLatin1String(";DATABASE=") + db + QLatin1String(";HOSTNAME=") + host
     1237        + QLatin1String(";PORT=") + QString::number(port) + QLatin1String(";UID=") + user
     1238        + QLatin1String(";PWD=") + password;
     1239
     1240
    12351241    SQLTCHAR connOut[SQL_MAX_OPTION_STRING_LENGTH];
    12361242    SQLSMALLINT cb;
     
    12511257    }
    12521258
    1253     d->user = user.toUpper();
     1259    d->user = user;
    12541260    setOpen(true);
    12551261    setOpenError(false);
     
    12961302    SQLHANDLE hStmt;
    12971303    QString catalog, schema, table;
    1298     qSplitTableQualifier(tableName.toUpper(), &catalog, &schema, &table);
     1304    qSplitTableQualifier(tableName, &catalog, &schema, &table);
    12991305    if (schema.isEmpty())
    13001306        schema = d->user;
     1307
     1308    if (isIdentifierEscaped(catalog, QSqlDriver::TableName))
     1309        catalog = stripDelimiters(catalog, QSqlDriver::TableName);
     1310    else
     1311        catalog = catalog.toUpper();
     1312
     1313    if (isIdentifierEscaped(schema, QSqlDriver::TableName))
     1314        schema = stripDelimiters(schema, QSqlDriver::TableName);
     1315    else
     1316        schema = schema.toUpper();
     1317
     1318    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     1319        table = stripDelimiters(table, QSqlDriver::TableName);
     1320    else
     1321        table = table.toUpper();
    13011322
    13021323    SQLRETURN r = SQLAllocHandle(SQL_HANDLE_STMT,
     
    13131334                        SQL_IS_UINTEGER);
    13141335
     1336
     1337    //Aside: szSchemaName and szTableName parameters of SQLColumns
     1338    //are case sensitive search patterns, so no escaping is used.
    13151339    r =  SQLColumns(hStmt,
    13161340                     NULL,
     
    13931417        QString fieldVal = qGetStringData(hStmt, 2, -1, isNull);
    13941418        QString userVal = qGetStringData(hStmt, 1, -1, isNull);
    1395         if (userVal != d->user)
     1419        QString user = d->user;
     1420        if ( isIdentifierEscaped(user, QSqlDriver::TableName))
     1421            user = stripDelimiters(user, QSqlDriver::TableName);
     1422        else
     1423            user = user.toUpper();
     1424
     1425        if (userVal != user)
    13961426            fieldVal = userVal + QLatin1Char('.') + fieldVal;
    13971427        tl.append(fieldVal);
     
    14241454    }
    14251455    QString catalog, schema, table;
    1426     qSplitTableQualifier(tablename.toUpper(), &catalog, &schema, &table);
     1456    qSplitTableQualifier(tablename, &catalog, &schema, &table);
     1457
     1458    if (isIdentifierEscaped(catalog, QSqlDriver::TableName))
     1459        catalog = stripDelimiters(catalog, QSqlDriver::TableName);
     1460    else
     1461        catalog = catalog.toUpper();
     1462
     1463    if (isIdentifierEscaped(schema, QSqlDriver::TableName))
     1464        schema = stripDelimiters(schema, QSqlDriver::TableName);
     1465    else
     1466        schema = schema.toUpper();
     1467
     1468    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     1469        table = stripDelimiters(table, QSqlDriver::TableName);
     1470    else
     1471        table = table.toUpper();
     1472
    14271473    r = SQLSetStmtAttr(hStmt,
    14281474                        SQL_ATTR_CURSOR_TYPE,
     
    14681514        case LastInsertId:
    14691515        case SimpleLocking:
    1470         case LowPrecisionNumbers:
    14711516        case EventNotifications:
    14721517            return false;
     
    14761521        case PreparedQueries:
    14771522        case PositionalPlaceholders:
     1523        case LowPrecisionNumbers:
     1524        case FinishQuery:
    14781525            return true;
    14791526        case Unicode:
    1480         // this is the query that shows the codepage for the types:
    1481         // select typename, codepage from syscat.datatypes
    1482 #ifdef UNICODE
    14831527            return true;
    1484 #else
    1485             return false;
    1486 #endif
    14871528    }
    14881529    return false;
     
    15981639{
    15991640    QString res = identifier;
    1600     if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {
     1641    if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) {
    16011642        res.replace(QLatin1Char('"'), QLatin1String("\"\""));
    16021643        res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
  • trunk/src/sql/drivers/db2/qsql_db2.h

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtSql module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
Note: See TracChangeset for help on using the changeset viewer.