From fbbad06751c93002754d4de26a73d43f139b82a0 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Thu, 14 Apr 2022 13:43:37 +0200 Subject: [PATCH] Sql: replace remaining uses of QLatin1String with QLatin1StringView Task-number: QTBUG-98434 Change-Id: Ia621f9d937649dda41a7b0d13a61e6f1397f6dde Reviewed-by: Volker Hilsheimer --- src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 4 +-- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 4 +-- src/plugins/sqldrivers/oci/qsql_oci.cpp | 4 +-- src/plugins/sqldrivers/psql/qsql_psql.cpp | 4 +-- src/sql/kernel/qsqldatabase.h | 8 +++--- src/sql/kernel/qsqlnulldriver_p.h | 4 +-- src/sql/kernel/qsqlquery.cpp | 10 ++++--- src/sql/models/qsqlquerymodel_p.h | 30 ++++++++++----------- 8 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index fda95c283b..cb7a604060 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -802,7 +802,7 @@ bool QIBaseResultPrivate::writeArray(int column, const QList &list) if (list.size() > arraySize) { error = "Array size mismatch: size of %1 is %2, size of provided list is %3"_L1; - error = error.arg(QLatin1String(sqlname)).arg(arraySize).arg(list.size()); + error = error.arg(QLatin1StringView(sqlname)).arg(arraySize).arg(list.size()); q->setLastError(QSqlError(error, ""_L1, QSqlError::StatementError)); return false; } @@ -810,7 +810,7 @@ bool QIBaseResultPrivate::writeArray(int column, const QList &list) if (!createArrayBuffer(ba.data(), list, qIBaseTypeName(desc.array_desc_dtype, inda->sqlvar[column].sqlscale < 0), 0, &desc, error)) { - q->setLastError(QSqlError(error.arg(QLatin1String(sqlname)), ""_L1, + q->setLastError(QSqlError(error.arg(QLatin1StringView(sqlname)), ""_L1, QSqlError::StatementError)); return false; } diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index b8dd32790f..efca8806da 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -1376,14 +1376,14 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const QStringList tl; QSqlQuery q(createResult()); if (type & QSql::Tables) { - QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1String(d->mysql->db) + "' and table_type = 'BASE TABLE'"_L1; + QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1StringView(d->mysql->db) + "' and table_type = 'BASE TABLE'"_L1; q.exec(sql); while (q.next()) tl.append(q.value(0).toString()); } if (type & QSql::Views) { - QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1String(d->mysql->db) + "' and table_type = 'VIEW'"_L1; + QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1StringView(d->mysql->db) + "' and table_type = 'VIEW'"_L1; q.exec(sql); while (q.next()) diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index 8638a070cc..6028eef882 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -2470,14 +2470,14 @@ static QString make_where_clause(const QString &user, Expression e) static const char joinC[][4] = { "or" , "and" }; static constexpr QLatin1Char bang[] = { u' ', u'!' }; - const QLatin1String join(joinC[e]); + const QLatin1StringView join(joinC[e]); QString result; result.reserve(sizeof sysUsers / sizeof *sysUsers * // max-sizeof(owner != and ) (9 + sizeof *sysUsers + 5)); for (const auto &sysUser : sysUsers) { - const QLatin1String l1(sysUser); + const QLatin1StringView l1(sysUser); if (l1 != user) result += "owner "_L1 + bang[e] + "= '"_L1 + l1 + "' "_L1 + join + u' '; } diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 722a75ee56..1c63cb7f32 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -1521,7 +1521,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const unsigned char *data = PQescapeBytea((const unsigned char*)ba.constData(), ba.size(), &len); #endif r += u'\''; - r += QLatin1String((const char*)data); + r += QLatin1StringView((const char*)data); r += u'\''; qPQfreemem(data); break; @@ -1658,7 +1658,7 @@ void QPSQLDriver::_q_handleNotification() PGnotify *notify = nullptr; while ((notify = PQnotifies(d->connection)) != nullptr) { - QString name(QLatin1String(notify->relname)); + QString name(QLatin1StringView(notify->relname)); if (d->seid.contains(name)) { QString payload; #if defined PG_VERSION_NUM && PG_VERSION_NUM-0 >= 70400 diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h index f233c72c19..75f4aba20e 100644 --- a/src/sql/kernel/qsqldatabase.h +++ b/src/sql/kernel/qsqldatabase.h @@ -114,15 +114,15 @@ public: static const char *defaultConnection; static QSqlDatabase addDatabase(const QString& type, - const QString& connectionName = QLatin1String(defaultConnection)); + const QString& connectionName = QLatin1StringView(defaultConnection)); static QSqlDatabase addDatabase(QSqlDriver* driver, - const QString& connectionName = QLatin1String(defaultConnection)); + const QString& connectionName = QLatin1StringView(defaultConnection)); static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName); static QSqlDatabase cloneDatabase(const QString &other, const QString& connectionName); - static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection), + static QSqlDatabase database(const QString& connectionName = QLatin1StringView(defaultConnection), bool open = true); static void removeDatabase(const QString& connectionName); - static bool contains(const QString& connectionName = QLatin1String(defaultConnection)); + static bool contains(const QString& connectionName = QLatin1StringView(defaultConnection)); static QStringList drivers(); static QStringList connectionNames(); static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator); diff --git a/src/sql/kernel/qsqlnulldriver_p.h b/src/sql/kernel/qsqlnulldriver_p.h index 7a40199d71..2d954cffcf 100644 --- a/src/sql/kernel/qsqlnulldriver_p.h +++ b/src/sql/kernel/qsqlnulldriver_p.h @@ -64,7 +64,7 @@ class QSqlNullResult : public QSqlResult public: inline explicit QSqlNullResult(const QSqlDriver* d): QSqlResult(d) { QSqlResult::setLastError( - QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); } + QSqlError(QLatin1StringView("Driver not loaded"), QLatin1StringView("Driver not loaded"), QSqlError::ConnectionError)); } protected: inline QVariant data(int) override { return QVariant(); } inline bool reset (const QString&) override { return false; } @@ -94,7 +94,7 @@ class QSqlNullDriver : public QSqlDriver public: inline QSqlNullDriver(): QSqlDriver() { QSqlDriver::setLastError( - QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); } + QSqlError(QLatin1StringView("Driver not loaded"), QLatin1StringView("Driver not loaded"), QSqlError::ConnectionError)); } inline bool hasFeature(DriverFeature) const override { return false; } inline bool open(const QString &, const QString &, const QString &, const QString &, int, const QString&) override { return false; } diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index afa4882b1b..f7932a6378 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -304,11 +304,13 @@ QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other) static void qInit(QSqlQuery *q, const QString& query, const QSqlDatabase &db) { QSqlDatabase database = db; - if (!database.isValid()) - database = QSqlDatabase::database(QLatin1String(QSqlDatabase::defaultConnection), false); - if (database.isValid()) { - *q = QSqlQuery(database.driver()->createResult()); + if (!database.isValid()) { + database = + QSqlDatabase::database(QLatin1StringView(QSqlDatabase::defaultConnection), false); } + if (database.isValid()) + *q = QSqlQuery(database.driver()->createResult()); + if (!query.isEmpty()) q->exec(query); } diff --git a/src/sql/models/qsqlquerymodel_p.h b/src/sql/models/qsqlquerymodel_p.h index 3772847eb1..70e2eb65cb 100644 --- a/src/sql/models/qsqlquerymodel_p.h +++ b/src/sql/models/qsqlquerymodel_p.h @@ -90,22 +90,22 @@ class QSqlQueryModelSql { public: // SQL keywords - inline const static QLatin1String as() { return QLatin1String("AS"); } - inline const static QLatin1String asc() { return QLatin1String("ASC"); } - inline const static QLatin1String comma() { return QLatin1String(","); } - inline const static QLatin1String desc() { return QLatin1String("DESC"); } - inline const static QLatin1String eq() { return QLatin1String("="); } + inline const static QLatin1StringView as() { return QLatin1StringView("AS"); } + inline const static QLatin1StringView asc() { return QLatin1StringView("ASC"); } + inline const static QLatin1StringView comma() { return QLatin1StringView(","); } + inline const static QLatin1StringView desc() { return QLatin1StringView("DESC"); } + inline const static QLatin1StringView eq() { return QLatin1StringView("="); } // "and" is a C++ keyword - inline const static QLatin1String et() { return QLatin1String("AND"); } - inline const static QLatin1String from() { return QLatin1String("FROM"); } - inline const static QLatin1String leftJoin() { return QLatin1String("LEFT JOIN"); } - inline const static QLatin1String on() { return QLatin1String("ON"); } - inline const static QLatin1String orderBy() { return QLatin1String("ORDER BY"); } - inline const static QLatin1String parenClose() { return QLatin1String(")"); } - inline const static QLatin1String parenOpen() { return QLatin1String("("); } - inline const static QLatin1String select() { return QLatin1String("SELECT"); } - inline const static QLatin1String sp() { return QLatin1String(" "); } - inline const static QLatin1String where() { return QLatin1String("WHERE"); } + inline const static QLatin1StringView et() { return QLatin1StringView("AND"); } + inline const static QLatin1StringView from() { return QLatin1StringView("FROM"); } + inline const static QLatin1StringView leftJoin() { return QLatin1StringView("LEFT JOIN"); } + inline const static QLatin1StringView on() { return QLatin1StringView("ON"); } + inline const static QLatin1StringView orderBy() { return QLatin1StringView("ORDER BY"); } + inline const static QLatin1StringView parenClose() { return QLatin1StringView(")"); } + inline const static QLatin1StringView parenOpen() { return QLatin1StringView("("); } + inline const static QLatin1StringView select() { return QLatin1StringView("SELECT"); } + inline const static QLatin1StringView sp() { return QLatin1StringView(" "); } + inline const static QLatin1StringView where() { return QLatin1StringView("WHERE"); } // Build expressions based on key words inline const static QString as(const QString &a, const QString &b) { return b.isEmpty() ? a : concat(concat(a, as()), b); }