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/ibase/qsql_ibase.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**
     
    5656#include <math.h>
    5757#include <qdebug.h>
     58#include <QVarLengthArray>
    5859
    5960QT_BEGIN_NAMESPACE
     
    6768enum { QIBaseChunkSize = SHRT_MAX / 2 };
    6869
    69 static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode,
    70                           QTextCodec *tc)
     70#if defined(FB_API_VER) && FB_API_VER >= 20
     71static bool getIBaseError(QString& msg, const ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc)
     72#else
     73static bool getIBaseError(QString& msg, ISC_STATUS* status, ISC_LONG &sqlcode, QTextCodec *tc)
     74#endif
    7175{
    7276    if (status[0] != 1 || status[1] <= 0)
     
    7680    sqlcode = isc_sqlcode(status);
    7781    char buf[512];
     82#if defined(FB_API_VER) && FB_API_VER >= 20
     83    while(fb_interpret(buf, 512, &status)) {
     84#else
    7885    while(isc_interprete(buf, &status)) {
     86#endif
    7987        if(!msg.isEmpty())
    8088            msg += QLatin1String(" - ");
     
    9098{
    9199    sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1));
     100    if (sqlda == (XSQLDA*)0) return;
    92101    sqlda->sqln = 1;
    93102    sqlda->sqld = 0;
     
    99108static void enlargeDA(XSQLDA *&sqlda, int n)
    100109{
    101     free(sqlda);
     110    if (sqlda != (XSQLDA*)0)
     111        free(sqlda);
    102112    sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(n));
     113    if (sqlda == (XSQLDA*)0) return;
    103114    sqlda->sqln = n;
    104115    sqlda->version = SQLDA_CURRENT_VERSION;
     
    119130        case SQL_TEXT:
    120131        case SQL_BLOB:
    121             sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen);
     132            sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen];
    122133            break;
    123134        case SQL_ARRAY:
    124             sqlda->sqlvar[i].sqldata = (char*)malloc(sizeof(ISC_QUAD));
     135            sqlda->sqlvar[i].sqldata = new char[sizeof(ISC_QUAD)];
    125136            memset(sqlda->sqlvar[i].sqldata, 0, sizeof(ISC_QUAD));
    126137            break;
    127138        case SQL_VARYING:
    128             sqlda->sqlvar[i].sqldata = (char*)malloc(sqlda->sqlvar[i].sqllen + sizeof(short));
     139            sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen + sizeof(short)];
    129140            break;
    130141        default:
     
    134145        }
    135146        if (sqlda->sqlvar[i].sqltype & 1) {
    136             sqlda->sqlvar[i].sqlind = (short*)malloc(sizeof(short));
     147            sqlda->sqlvar[i].sqlind = new short[1];
    137148            *(sqlda->sqlvar[i].sqlind) = 0;
    138149        } else {
     
    147158        return;
    148159    for (int i = 0; i < sqlda->sqld; ++i) {
    149         free(sqlda->sqlvar[i].sqlind);
    150         free(sqlda->sqlvar[i].sqldata);
     160        delete [] sqlda->sqlvar[i].sqlind;
     161        delete [] sqlda->sqlvar[i].sqldata;
    151162    }
    152163    free(sqlda);
     
    293304    ISC_LONG bufferLength;
    294305    ISC_LONG eventId;
    295    
     306
    296307    enum QIBaseSubscriptionState { Starting, Subscribed, Finished };
    297308    QIBaseSubscriptionState subscriptionState;
     
    444455    ba.resize(read);
    445456
    446     bool isErr = (status[1] == isc_segstr_eof ? false : 
    447                     isError(QT_TRANSLATE_NOOP("QIBaseResult", 
     457    bool isErr = (status[1] == isc_segstr_eof ? false :
     458                    isError(QT_TRANSLATE_NOOP("QIBaseResult",
    448459                                                "Unable to read BLOB"),
    449460                                                QSqlError::StatementError));
     
    512523                    else
    513524                        valList.append(QString::fromUtf8(buffer, o));
    514                    
     525
    515526                    buffer += strLen;
    516527                }
     
    577588    int arraySize = 1, subArraySize;
    578589    short dimensions = desc.array_desc_dimensions;
    579     short *numElements = new short[dimensions];
     590    QVarLengthArray<short> numElements(dimensions);
    580591
    581592    for(int i = 0; i < dimensions; ++i) {
     
    606617        return list;
    607618
    608     readArrayBuffer(list, ba.data(), 0, numElements, &desc, tc);
    609 
    610     delete[] numElements;
     619    readArrayBuffer(list, ba.data(), 0, numElements.data(), &desc, tc);
    611620
    612621    return QVariant(list);
     
    639648}
    640649
    641 static char* qFillBufferWithString(char *buffer, const QString& string, 
    642                                    short buflen, bool varying, bool array, 
     650static char* qFillBufferWithString(char *buffer, const QString& string,
     651                                   short buflen, bool varying, bool array,
    643652                                   QTextCodec *tc)
    644653{
     
    872881bool QIBaseResult::prepare(const QString& query)
    873882{
    874     //qDebug("prepare: %s\n", qPrintable(query));
     883//     qDebug("prepare: %s", qPrintable(query));
    875884    if (!driver() || !driver()->isOpen() || driver()->isOpenError())
    876885        return false;
     
    880889
    881890    createDA(d->sqlda);
     891    if (d->sqlda == (XSQLDA*)0) {
     892        qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory";
     893        return false;
     894    }
     895
    882896    createDA(d->inda);
     897    if (d->inda == (XSQLDA*)0){
     898        qWarning()<<"QIOBaseResult: createDA():  failed to allocate memory";
     899        return false;
     900    }
    883901
    884902    if (!d->transaction())
     
    901919    if (d->inda->sqld > d->inda->sqln) {
    902920        enlargeDA(d->inda, d->inda->sqld);
     921        if (d->inda == (XSQLDA*)0) {
     922            qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory";
     923            return false;
     924        }
    903925
    904926        isc_dsql_describe_bind(d->status, &d->stmt, FBVERSION, d->inda);
     
    911933        // need more field descriptors
    912934        enlargeDA(d->sqlda, d->sqlda->sqld);
     935        if (d->sqlda == (XSQLDA*)0) {
     936            qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory";
     937            return false;
     938        }
    913939
    914940        isc_dsql_describe(d->status, &d->stmt, FBVERSION, d->sqlda);
     
    9781004            case SQL_LONG:
    9791005                if (d->inda->sqlvar[para].sqlscale < 0)
    980                     *((long*)d->inda->sqlvar[para].sqldata) = 
     1006                    *((long*)d->inda->sqlvar[para].sqldata) =
    9811007                        (long)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1));
    9821008                else
     
    9851011            case SQL_SHORT:
    9861012                if (d->inda->sqlvar[para].sqlscale < 0)
    987                     *((short*)d->inda->sqlvar[para].sqldata) = 
     1013                    *((short*)d->inda->sqlvar[para].sqldata) =
    9881014                        (short)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1));
    9891015                else
     
    10261052
    10271053    if (ok) {
    1028         if (colCount()) {
     1054        if (colCount() && d->queryType != isc_info_sql_stmt_exec_procedure) {
    10291055            isc_dsql_free_statement(d->status, &d->stmt, DSQL_close);
    10301056            if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to close statement")))
     
    10401066
    10411067        // Not all stored procedures necessarily return values.
    1042         if (d->queryType == isc_info_sql_stmt_exec_procedure && d->sqlda->sqld == 0)
     1068        if (d->queryType == isc_info_sql_stmt_exec_procedure && d->sqlda && d->sqlda->sqld == 0)
    10431069            delDA(d->sqlda);
    10441070
     
    10981124            QVariant v;
    10991125            v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0));
     1126            if(v.type() == QVariant::Double) {
     1127                switch(numericalPrecisionPolicy()) {
     1128                case QSql::LowPrecisionInt32:
     1129                    v.convert(QVariant::Int);
     1130                    break;
     1131                case QSql::LowPrecisionInt64:
     1132                    v.convert(QVariant::LongLong);
     1133                    break;
     1134                case QSql::HighPrecision:
     1135                    v.convert(QVariant::String);
     1136                    break;
     1137                }
     1138            }
    11001139            row[idx] = v;
    11011140            continue;
     
    11621201            row[idx] = QVariant();
    11631202            break;
     1203        }
     1204        if (d->sqlda->sqlvar[i].sqlscale < 0) {
     1205            QVariant v = row[idx];
     1206            switch(numericalPrecisionPolicy()) {
     1207            case QSql::LowPrecisionInt32:
     1208                if(v.convert(QVariant::Int))
     1209                    row[idx]=v;
     1210                break;
     1211            case QSql::LowPrecisionInt64:
     1212                if(v.convert(QVariant::LongLong))
     1213                    row[idx]=v;
     1214                break;
     1215            case QSql::LowPrecisionDouble:
     1216                if(v.convert(QVariant::Double))
     1217                    row[idx]=v;
     1218                break;
     1219            case QSql::HighPrecision:
     1220                if(v.convert(QVariant::String))
     1221                    row[idx]=v;
     1222                break;
     1223            }
    11641224        }
    11651225    }
     
    12371297        cCountType = isc_info_req_insert_count;
    12381298        break;
     1299    default:
     1300        qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")";
     1301        return -1;
    12391302    }
    12401303
     
    12711334        QSqlField f(QString::fromLatin1(v.aliasname, v.aliasname_length).simplified(),
    12721335                    qIBaseTypeName2(v.sqltype, v.sqlscale < 0));
    1273         QSqlQuery q(new QIBaseResult(d->db));
    1274         q.setForwardOnly(true);
    1275         q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG "
    1276                 "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b "
    1277                 "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE "
    1278                 "AND a.RDB$RELATION_NAME = '") + QString::fromAscii(v.relname, v.relname_length).toUpper() + QLatin1String("' "
    1279                 "AND a.RDB$FIELD_NAME = '") + QString::fromAscii(v.sqlname, v.sqlname_length).toUpper() + QLatin1String("' "));
    1280         if(q.first()) {
    1281             if(v.sqlscale < 0) {
    1282                 f.setLength(q.value(0).toInt());
    1283                 f.setPrecision(qAbs(q.value(1).toInt()));
    1284             } else {
    1285                 f.setLength(q.value(2).toInt());
    1286                 f.setPrecision(0);
     1336        f.setLength(v.sqllen);
     1337        f.setPrecision(qAbs(v.sqlscale));
     1338        f.setRequiredStatus((v.sqltype & 1) == 0 ? QSqlField::Required : QSqlField::Optional);
     1339        if(v.sqlscale < 0) {
     1340            QSqlQuery q(new QIBaseResult(d->db));
     1341            q.setForwardOnly(true);
     1342            q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG "
     1343                    "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b "
     1344                    "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE "
     1345                    "AND a.RDB$RELATION_NAME = '") + QString::fromAscii(v.relname, v.relname_length).toUpper() + QLatin1String("' "
     1346                    "AND a.RDB$FIELD_NAME = '") + QString::fromAscii(v.sqlname, v.sqlname_length).toUpper() + QLatin1String("' "));
     1347            if(q.first()) {
     1348                if(v.sqlscale < 0) {
     1349                    f.setLength(q.value(0).toInt());
     1350                    f.setPrecision(qAbs(q.value(1).toInt()));
     1351                } else {
     1352                    f.setLength(q.value(2).toInt());
     1353                    f.setPrecision(0);
     1354                }
     1355                f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional);
    12871356            }
    1288             f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional);
    1289         }
    1290         else {
    1291             f.setLength(0);
    1292             f.setPrecision(0);
    1293             f.setRequiredStatus(QSqlField::Unknown);
    12941357        }
    12951358        f.setSqlType(v.sqltype);
     
    13341397    case BatchOperations:
    13351398    case SimpleLocking:
    1336     case LowPrecisionNumbers:
    13371399    case FinishQuery:
    13381400    case MultipleResultSets:
     
    13441406    case BLOB:
    13451407    case EventNotifications:
     1408    case LowPrecisionNumbers:
    13461409        return true;
    13471410    }
     
    15531616    QSqlQuery q(createResult());
    15541617    q.setForwardOnly(true);
    1555 
     1618    QString table = tablename;
     1619    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     1620        table = stripDelimiters(table, QSqlDriver::TableName);
     1621    else
     1622        table = table.toUpper();
    15561623    q.exec(QLatin1String("SELECT a.RDB$FIELD_NAME, b.RDB$FIELD_TYPE, b.RDB$FIELD_LENGTH, "
    15571624           "b.RDB$FIELD_SCALE, b.RDB$FIELD_PRECISION, a.RDB$NULL_FLAG "
    15581625           "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b "
    15591626           "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE "
    1560            "AND a.RDB$RELATION_NAME = '") + tablename.toUpper() + QLatin1String("' "
     1627           "AND a.RDB$RELATION_NAME = '") + table + QLatin1String("' "
    15611628           "ORDER BY a.RDB$FIELD_POSITION"));
    15621629
     
    15861653        return index;
    15871654
     1655    QString tablename = table;
     1656    if (isIdentifierEscaped(tablename, QSqlDriver::TableName))
     1657        tablename = stripDelimiters(tablename, QSqlDriver::TableName);
     1658    else
     1659        tablename = tablename.toUpper();
     1660
    15881661    QSqlQuery q(createResult());
    15891662    q.setForwardOnly(true);
     
    15911664           "FROM RDB$RELATION_CONSTRAINTS a, RDB$INDEX_SEGMENTS b, RDB$RELATION_FIELDS c, RDB$FIELDS d "
    15921665           "WHERE a.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' "
    1593            "AND a.RDB$RELATION_NAME = '") + table.toUpper() +
     1666           "AND a.RDB$RELATION_NAME = '") + tablename +
    15941667           QLatin1String(" 'AND a.RDB$INDEX_NAME = b.RDB$INDEX_NAME "
    15951668           "AND c.RDB$RELATION_NAME = a.RDB$RELATION_NAME "
     
    16681741    QIBaseDriver *driver = qBufferDriverMap()->value(result);
    16691742    qMutex()->unlock();
    1670    
     1743
    16711744    // We use an asynchronous call (i.e., queued connection) because the event callback
    16721745    // is executed in a different thread than the one in which the driver lives.
     
    17171790
    17181791    if (status[0] == 1 && status[1]) {
    1719         setLastError(QSqlError(QString(QLatin1String("Could not subscribe to event notifications for %1.")).arg(name)));
     1792        setLastError(QSqlError(QString::fromLatin1("Could not subscribe to event notifications for %1.").arg(name)));
    17201793        d->eventBuffers.remove(name);
    17211794        qFreeEventBuffer(eBuffer);
     
    17451818
    17461819    if (status[0] == 1 && status[1]) {
    1747         setLastError(QSqlError(QString(QLatin1String("Could not unsubscribe from event notifications for %1.")).arg(name)));
     1820        setLastError(QSqlError(QString::fromLatin1("Could not unsubscribe from event notifications for %1.").arg(name)));
    17481821        return false;
    17491822    }
     
    18031876{
    18041877    QString res = identifier;
    1805     if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {
     1878    if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) {
    18061879        res.replace(QLatin1Char('"'), QLatin1String("\"\""));
    18071880        res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
  • trunk/src/sql/drivers/ibase/qsql_ibase.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.