diff options
Diffstat (limited to 'src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp')
-rw-r--r-- | src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 126 |
1 files changed, 46 insertions, 80 deletions
diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index 54d734683b..51a3908867 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtSql module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qsql_sqlite_p.h" @@ -74,18 +38,20 @@ Q_DECLARE_METATYPE(sqlite3_stmt*) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static QString _q_escapeIdentifier(const QString &identifier, QSqlDriver::IdentifierType type) { QString res = identifier; // If it contains [ and ] then we assume it to be escaped properly already as this indicates // the syntax is exactly how it should be - if (identifier.contains(QLatin1Char('[')) && identifier.contains(QLatin1Char(']'))) + if (identifier.contains(u'[') && identifier.contains(u']')) return res; - if (!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"'))) { - res.replace(QLatin1Char('"'), QLatin1String("\"\"")); - res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); + if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"')) { + res.replace(u'"', "\"\""_L1); + res.prepend(u'"').append(u'"'); if (type == QSqlDriver::TableName) - res.replace(QLatin1Char('.'), QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } @@ -94,18 +60,16 @@ static int qGetColumnType(const QString &tpName) { const QString typeName = tpName.toLower(); - if (typeName == QLatin1String("integer") - || typeName == QLatin1String("int")) + if (typeName == "integer"_L1 || typeName == "int"_L1) return QMetaType::Int; - if (typeName == QLatin1String("double") - || typeName == QLatin1String("float") - || typeName == QLatin1String("real") - || typeName.startsWith(QLatin1String("numeric"))) + if (typeName == "double"_L1 + || typeName == "float"_L1 + || typeName == "real"_L1 + || typeName.startsWith("numeric"_L1)) return QMetaType::Double; - if (typeName == QLatin1String("blob")) + if (typeName == "blob"_L1) return QMetaType::QByteArray; - if (typeName == QLatin1String("boolean") - || typeName == QLatin1String("bool")) + if (typeName == "boolean"_L1 || typeName == "bool"_L1) return QMetaType::Bool; return QMetaType::QString; } @@ -209,10 +173,10 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset) for (int i = 0; i < nCols; ++i) { QString colName = QString(reinterpret_cast<const QChar *>( sqlite3_column_name16(stmt, i)) - ).remove(QLatin1Char('"')); + ).remove(u'"'); const QString tableName = QString(reinterpret_cast<const QChar *>( sqlite3_column_table_name16(stmt, i)) - ).remove(QLatin1Char('"')); + ).remove(u'"'); // must use typeName for resolving the type to match QSqliteDriver::record QString typeName = QString(reinterpret_cast<const QChar *>( sqlite3_column_decltype16(stmt, i))); @@ -728,29 +692,29 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c bool openUriOption = false; bool useExtendedResultCodes = true; #if QT_CONFIG(regularexpression) - static const QLatin1String regexpConnectOption = QLatin1String("QSQLITE_ENABLE_REGEXP"); + static const auto regexpConnectOption = "QSQLITE_ENABLE_REGEXP"_L1; bool defineRegexp = false; int regexpCacheSize = 25; #endif - const auto opts = QStringView{conOpts}.split(QLatin1Char(';')); + const auto opts = QStringView{conOpts}.split(u';'); for (auto option : opts) { option = option.trimmed(); - if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT"))) { + if (option.startsWith("QSQLITE_BUSY_TIMEOUT"_L1)) { option = option.mid(20).trimmed(); - if (option.startsWith(QLatin1Char('='))) { + if (option.startsWith(u'=')) { bool ok; const int nt = option.mid(1).trimmed().toInt(&ok); if (ok) timeOut = nt; } - } else if (option == QLatin1String("QSQLITE_OPEN_READONLY")) { + } else if (option == "QSQLITE_OPEN_READONLY"_L1) { openReadOnlyOption = true; - } else if (option == QLatin1String("QSQLITE_OPEN_URI")) { + } else if (option == "QSQLITE_OPEN_URI"_L1) { openUriOption = true; - } else if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE")) { + } else if (option == "QSQLITE_ENABLE_SHARED_CACHE"_L1) { sharedCache = true; - } else if (option == QLatin1String("QSQLITE_NO_USE_EXTENDED_RESULT_CODES")) { + } else if (option == "QSQLITE_NO_USE_EXTENDED_RESULT_CODES"_L1) { useExtendedResultCodes = false; } #if QT_CONFIG(regularexpression) @@ -758,7 +722,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c option = option.mid(regexpConnectOption.size()).trimmed(); if (option.isEmpty()) { defineRegexp = true; - } else if (option.startsWith(QLatin1Char('='))) { + } else if (option.startsWith(u'=')) { bool ok = false; const int cacheSize = option.mid(1).trimmed().toInt(&ok); if (ok) { @@ -841,7 +805,7 @@ bool QSQLiteDriver::beginTransaction() return false; QSqlQuery q(createResult()); - if (!q.exec(QLatin1String("BEGIN"))) { + if (!q.exec("BEGIN"_L1)) { setLastError(QSqlError(tr("Unable to begin transaction"), q.lastError().databaseText(), QSqlError::TransactionError)); return false; @@ -856,7 +820,7 @@ bool QSQLiteDriver::commitTransaction() return false; QSqlQuery q(createResult()); - if (!q.exec(QLatin1String("COMMIT"))) { + if (!q.exec("COMMIT"_L1)) { setLastError(QSqlError(tr("Unable to commit transaction"), q.lastError().databaseText(), QSqlError::TransactionError)); return false; @@ -871,7 +835,7 @@ bool QSQLiteDriver::rollbackTransaction() return false; QSqlQuery q(createResult()); - if (!q.exec(QLatin1String("ROLLBACK"))) { + if (!q.exec("ROLLBACK"_L1)) { setLastError(QSqlError(tr("Unable to rollback transaction"), q.lastError().databaseText(), QSqlError::TransactionError)); return false; @@ -889,14 +853,14 @@ QStringList QSQLiteDriver::tables(QSql::TableType type) const QSqlQuery q(createResult()); q.setForwardOnly(true); - QString sql = QLatin1String("SELECT name FROM sqlite_master WHERE %1 " - "UNION ALL SELECT name FROM sqlite_temp_master WHERE %1"); + QString sql = "SELECT name FROM sqlite_master WHERE %1 " + "UNION ALL SELECT name FROM sqlite_temp_master WHERE %1"_L1; if ((type & QSql::Tables) && (type & QSql::Views)) - sql = sql.arg(QLatin1String("type='table' OR type='view'")); + sql = sql.arg("type='table' OR type='view'"_L1); else if (type & QSql::Tables) - sql = sql.arg(QLatin1String("type='table'")); + sql = sql.arg("type='table'"_L1); else if (type & QSql::Views) - sql = sql.arg(QLatin1String("type='view'")); + sql = sql.arg("type='view'"_L1); else sql.clear(); @@ -907,7 +871,7 @@ QStringList QSQLiteDriver::tables(QSql::TableType type) const if (type & QSql::SystemTables) { // there are no internal tables beside this one: - res.append(QLatin1String("sqlite_master")); + res.append("sqlite_master"_L1); } return res; @@ -917,15 +881,15 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only { QString schema; QString table(tableName); - const int indexOfSeparator = tableName.indexOf(QLatin1Char('.')); + const qsizetype indexOfSeparator = tableName.indexOf(u'.'); if (indexOfSeparator > -1) { - const int indexOfCloseBracket = tableName.indexOf(QLatin1Char(']')); + const qsizetype indexOfCloseBracket = tableName.indexOf(u']'); if (indexOfCloseBracket != tableName.size() - 1) { // Handles a case like databaseName.tableName schema = tableName.left(indexOfSeparator + 1); table = tableName.mid(indexOfSeparator + 1); } else { - const int indexOfOpenBracket = tableName.lastIndexOf(QLatin1Char('['), indexOfCloseBracket); + const qsizetype indexOfOpenBracket = tableName.lastIndexOf(u'[', indexOfCloseBracket); if (indexOfOpenBracket > 0) { // Handles a case like databaseName.[tableName] schema = tableName.left(indexOfOpenBracket); @@ -933,8 +897,8 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only } } } - q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + - _q_escapeIdentifier(table, QSqlDriver::TableName) + QLatin1Char(')')); + q.exec("PRAGMA "_L1 + schema + "table_info ("_L1 + + _q_escapeIdentifier(table, QSqlDriver::TableName) + u')'); QSqlIndex ind; while (q.next()) { bool isPk = q.value(5).toInt(); @@ -942,14 +906,14 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only continue; QString typeName = q.value(2).toString().toLower(); QString defVal = q.value(4).toString(); - if (!defVal.isEmpty() && defVal.at(0) == QLatin1Char('\'')) { - const int end = defVal.lastIndexOf(QLatin1Char('\'')); + if (!defVal.isEmpty() && defVal.at(0) == u'\'') { + const int end = defVal.lastIndexOf(u'\''); if (end > 0) defVal = defVal.mid(1, end - 1); } QSqlField fld(q.value(1).toString(), QMetaType(qGetColumnType(typeName)), tableName); - if (isPk && (typeName == QLatin1String("integer"))) + if (isPk && (typeName == "integer"_L1)) // INTEGER PRIMARY KEY fields are auto-generated in sqlite // INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY! fld.setAutoValue(true); @@ -1066,3 +1030,5 @@ void QSQLiteDriver::handleNotification(const QString &tableName, qint64 rowid) } QT_END_NAMESPACE + +#include "moc_qsql_sqlite_p.cpp" |