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/sqlite/qsql_sqlite.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**
     
    6464
    6565QT_BEGIN_NAMESPACE
     66
     67static QString _q_escapeIdentifier(const QString &identifier)
     68{
     69    QString res = identifier;
     70    if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {
     71        res.replace(QLatin1Char('"'), QLatin1String("\"\""));
     72        res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
     73        res.replace(QLatin1Char('.'), QLatin1String("\".\""));
     74    }
     75    return res;
     76}
    6677
    6778static QVariant::Type qGetColumnType(const QString &tpName)
     
    112123    sqlite3_stmt *stmt;
    113124
    114     uint skippedStatus: 1; // the status of the fetchNext() that's skipped
    115     uint skipRow: 1; // skip the next fetchNext()?
    116     uint utf8: 1;
     125    bool skippedStatus; // the status of the fetchNext() that's skipped
     126    bool skipRow; // skip the next fetchNext()?
    117127    QSqlRecord rInf;
    118     QSql::NumericalPrecisionPolicy precisionPolicy;
     128    QVector<QVariant> firstRow;
    119129};
    120130
    121 static const uint initial_cache_size = 128;
    122 
    123131QSQLiteResultPrivate::QSQLiteResultPrivate(QSQLiteResult* res) : q(res), access(0),
    124     stmt(0), skippedStatus(false), skipRow(false), utf8(false), precisionPolicy(QSql::HighPrecision)
     132    stmt(0), skippedStatus(false), skipRow(false)
    125133{
    126134}
     
    182190        Q_ASSERT(!initialFetch);
    183191        skipRow = false;
     192        for(int i=0;i<firstRow.count();i++)
     193            values[i]=firstRow[i];
    184194        return skippedStatus;
    185195    }
    186196    skipRow = initialFetch;
     197
     198    if(initialFetch) {
     199        firstRow.clear();
     200        firstRow.resize(sqlite3_column_count(stmt));
     201    }
    187202
    188203    if (!stmt) {
     
    213228                break;
    214229            case SQLITE_FLOAT:
    215                 switch(precisionPolicy) {
     230                switch(q->numericalPrecisionPolicy()) {
    216231                    case QSql::LowPrecisionInt32:
    217232                        values[i + idx] = sqlite3_column_int(stmt, i);
     
    221236                        break;
    222237                    case QSql::LowPrecisionDouble:
    223                         values[i + idx] = sqlite3_column_double(stmt, i);
    224                         break;
    225238                    case QSql::HighPrecision:
    226239                    default:
    227                         values[i + idx] = QString::fromUtf16(static_cast<const ushort *>(
    228                                             sqlite3_column_text16(stmt, i)),
    229                                             sqlite3_column_bytes16(stmt, i) / sizeof(ushort));
     240                        values[i + idx] = sqlite3_column_double(stmt, i);
    230241                        break;
    231242                };
     
    290301            sqlite3_reset(d->stmt);
    291302        break;
    292     case QSqlResult::SetNumericalPrecision:
    293         Q_ASSERT(data);
    294         d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);
    295         break;
    296303    default:
    297         QSqlResult::virtual_hook(id, data);
     304        QSqlCachedResult::virtual_hook(id, data);
    298305    }
    299306}
     
    400407        return false;
    401408    }
    402     d->skippedStatus = d->fetchNext(cache(), 0, true);
     409    d->skippedStatus = d->fetchNext(d->firstRow, 0, true);
    403410    if (lastError().isValid()) {
    404411        setSelect(false);
     
    482489    case SimpleLocking:
    483490    case FinishQuery:
     491    case LowPrecisionNumbers:
    484492        return true;
    485493    case QuerySize:
    486494    case NamedPlaceholders:
    487495    case BatchOperations:
    488     case LowPrecisionNumbers:
    489496    case EventNotifications:
    490497    case MultipleResultSets:
     
    499506
    500507    opts.remove(QLatin1Char(' '));
    501     if (opts.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
    502         bool ok;
    503         int nt = opts.mid(21).toInt(&ok);
    504         if (ok)
    505             return nt;
     508    foreach(QString option, opts.split(QLatin1Char(';'))) {
     509        if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
     510            bool ok;
     511            int nt = option.mid(21).toInt(&ok);
     512            if (ok)
     513                return nt;
     514        }
    506515    }
    507516    return DefaultTimeout;
     517}
     518
     519static int qGetSqliteOpenMode(QString opts)
     520{
     521    opts.remove(QLatin1Char(' '));
     522    foreach(QString option, opts.split(QLatin1Char(';'))) {
     523        if (option == QLatin1String("QSQLITE_OPEN_READONLY"))
     524                return SQLITE_OPEN_READONLY;
     525    }
     526    return SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
    508527}
    509528
     
    520539        return false;
    521540
    522     if (sqlite3_open16(db.constData(), &d->access) == SQLITE_OK) {
     541    if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, qGetSqliteOpenMode(conOpts), NULL) == SQLITE_OK) {
    523542        sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts));
    524543        setOpen(true);
     
    632651    QString schema;
    633652    QString table(tableName);
    634     int indexOfSeparator = tableName.indexOf(QLatin1String("."));
     653    int indexOfSeparator = tableName.indexOf(QLatin1Char('.'));
    635654    if (indexOfSeparator > -1) {
    636         schema = tableName.left(indexOfSeparator).append(QLatin1String("."));
     655        schema = tableName.left(indexOfSeparator).append(QLatin1Char('.'));
    637656        table = tableName.mid(indexOfSeparator + 1);
    638657    }
    639     q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info ('") + table + QLatin1String("')"));
     658    q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")"));
    640659
    641660    QSqlIndex ind;
     
    662681        return QSqlIndex();
    663682
     683    QString table = tblname;
     684    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     685        table = stripDelimiters(table, QSqlDriver::TableName);
     686
    664687    QSqlQuery q(createResult());
    665688    q.setForwardOnly(true);
    666     return qGetTableInfo(q, tblname, true);
     689    return qGetTableInfo(q, table, true);
    667690}
    668691
     
    672695        return QSqlRecord();
    673696
     697    QString table = tbl;
     698    if (isIdentifierEscaped(table, QSqlDriver::TableName))
     699        table = stripDelimiters(table, QSqlDriver::TableName);
     700
    674701    QSqlQuery q(createResult());
    675702    q.setForwardOnly(true);
    676     return qGetTableInfo(q, tbl);
     703    return qGetTableInfo(q, table);
    677704}
    678705
     
    682709}
    683710
    684 QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType /*type*/) const
    685 {
    686     QString res = identifier;
    687     if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) {
    688         res.replace(QLatin1Char('"'), QLatin1String("\"\""));
    689         res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
    690         res.replace(QLatin1Char('.'), QLatin1String("\".\""));
    691     }
    692     return res;
     711QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const
     712{
     713    Q_UNUSED(type);
     714    return _q_escapeIdentifier(identifier);
    693715}
    694716
  • trunk/src/sql/drivers/sqlite/qsql_sqlite.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.