Changeset 561 for trunk/src/sql/drivers/sqlite
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/sql/drivers/sqlite/qsql_sqlite.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtSql module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 64 64 65 65 QT_BEGIN_NAMESPACE 66 67 static 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 } 66 77 67 78 static QVariant::Type qGetColumnType(const QString &tpName) … … 112 123 sqlite3_stmt *stmt; 113 124 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()? 117 127 QSqlRecord rInf; 118 Q Sql::NumericalPrecisionPolicy precisionPolicy;128 QVector<QVariant> firstRow; 119 129 }; 120 130 121 static const uint initial_cache_size = 128;122 123 131 QSQLiteResultPrivate::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) 125 133 { 126 134 } … … 182 190 Q_ASSERT(!initialFetch); 183 191 skipRow = false; 192 for(int i=0;i<firstRow.count();i++) 193 values[i]=firstRow[i]; 184 194 return skippedStatus; 185 195 } 186 196 skipRow = initialFetch; 197 198 if(initialFetch) { 199 firstRow.clear(); 200 firstRow.resize(sqlite3_column_count(stmt)); 201 } 187 202 188 203 if (!stmt) { … … 213 228 break; 214 229 case SQLITE_FLOAT: 215 switch( precisionPolicy) {230 switch(q->numericalPrecisionPolicy()) { 216 231 case QSql::LowPrecisionInt32: 217 232 values[i + idx] = sqlite3_column_int(stmt, i); … … 221 236 break; 222 237 case QSql::LowPrecisionDouble: 223 values[i + idx] = sqlite3_column_double(stmt, i);224 break;225 238 case QSql::HighPrecision: 226 239 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); 230 241 break; 231 242 }; … … 290 301 sqlite3_reset(d->stmt); 291 302 break; 292 case QSqlResult::SetNumericalPrecision:293 Q_ASSERT(data);294 d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);295 break;296 303 default: 297 QSql Result::virtual_hook(id, data);304 QSqlCachedResult::virtual_hook(id, data); 298 305 } 299 306 } … … 400 407 return false; 401 408 } 402 d->skippedStatus = d->fetchNext( cache(), 0, true);409 d->skippedStatus = d->fetchNext(d->firstRow, 0, true); 403 410 if (lastError().isValid()) { 404 411 setSelect(false); … … 482 489 case SimpleLocking: 483 490 case FinishQuery: 491 case LowPrecisionNumbers: 484 492 return true; 485 493 case QuerySize: 486 494 case NamedPlaceholders: 487 495 case BatchOperations: 488 case LowPrecisionNumbers:489 496 case EventNotifications: 490 497 case MultipleResultSets: … … 499 506 500 507 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 } 506 515 } 507 516 return DefaultTimeout; 517 } 518 519 static 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; 508 527 } 509 528 … … 520 539 return false; 521 540 522 if (sqlite3_open 16(db.constData(), &d->access) == SQLITE_OK) {541 if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, qGetSqliteOpenMode(conOpts), NULL) == SQLITE_OK) { 523 542 sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts)); 524 543 setOpen(true); … … 632 651 QString schema; 633 652 QString table(tableName); 634 int indexOfSeparator = tableName.indexOf(QLatin1 String("."));653 int indexOfSeparator = tableName.indexOf(QLatin1Char('.')); 635 654 if (indexOfSeparator > -1) { 636 schema = tableName.left(indexOfSeparator).append(QLatin1 String("."));655 schema = tableName.left(indexOfSeparator).append(QLatin1Char('.')); 637 656 table = tableName.mid(indexOfSeparator + 1); 638 657 } 639 q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info ( '") + table + QLatin1String("')"));658 q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + _q_escapeIdentifier(table) + QLatin1String(")")); 640 659 641 660 QSqlIndex ind; … … 662 681 return QSqlIndex(); 663 682 683 QString table = tblname; 684 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 685 table = stripDelimiters(table, QSqlDriver::TableName); 686 664 687 QSqlQuery q(createResult()); 665 688 q.setForwardOnly(true); 666 return qGetTableInfo(q, t blname, true);689 return qGetTableInfo(q, table, true); 667 690 } 668 691 … … 672 695 return QSqlRecord(); 673 696 697 QString table = tbl; 698 if (isIdentifierEscaped(table, QSqlDriver::TableName)) 699 table = stripDelimiters(table, QSqlDriver::TableName); 700 674 701 QSqlQuery q(createResult()); 675 702 q.setForwardOnly(true); 676 return qGetTableInfo(q, t bl);703 return qGetTableInfo(q, table); 677 704 } 678 705 … … 682 709 } 683 710 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; 711 QString QSQLiteDriver::escapeIdentifier(const QString &identifier, IdentifierType type) const 712 { 713 Q_UNUSED(type); 714 return _q_escapeIdentifier(identifier); 693 715 } 694 716 -
trunk/src/sql/drivers/sqlite/qsql_sqlite.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtSql module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 **
Note:
See TracChangeset
for help on using the changeset viewer.