diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-04-14 13:21:36 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-04-19 19:40:04 +0200 |
commit | 128785d0fa0dc05dbe5ef2d5c8c3ba09b7c48546 (patch) | |
tree | 324c5356f4412528ea8a03a786fe1aaa183ad88c | |
parent | 917b4d3802f3c2102021610cbf977403a3d4c21a (diff) | |
download | qtbase-128785d0fa0dc05dbe5ef2d5c8c3ba09b7c48546.tar.gz |
Sql: use _L1 for for creating Latin-1 string literals
Task-number: QTBUG-98434
Change-Id: Ie12ca82fd912617eabe4f602c08914f12878cb32
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
22 files changed, 356 insertions, 327 deletions
diff --git a/src/plugins/sqldrivers/db2/main.cpp b/src/plugins/sqldrivers/db2/main.cpp index 97338b8eef..e44f1f9793 100644 --- a/src/plugins/sqldrivers/db2/main.cpp +++ b/src/plugins/sqldrivers/db2/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QDB2DriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QDB2DriverPlugin::QDB2DriverPlugin() QSqlDriver* QDB2DriverPlugin::create(const QString &name) { - if (name == QLatin1String("QDB2")) { + if (name == "QDB2"_L1) { QDB2Driver* driver = new QDB2Driver(); return driver; } diff --git a/src/plugins/sqldrivers/db2/qsql_db2.cpp b/src/plugins/sqldrivers/db2/qsql_db2.cpp index d66c1eb676..f19a78aa48 100644 --- a/src/plugins/sqldrivers/db2/qsql_db2.cpp +++ b/src/plugins/sqldrivers/db2/qsql_db2.cpp @@ -65,6 +65,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static const int COLNAMESIZE = 255; // Based on what is mentioned in the documentation here: // https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/sqlref/src/tpc/db2z_limits.html @@ -554,13 +556,13 @@ static bool qMakeStatement(QDB2ResultPrivate* d, bool forwardOnly, bool setForwa d->drv_d_func()->hDbc, &d->hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QDB2Result::reset: Unable to allocate statement handle"), d); + qSqlWarning("QDB2Result::reset: Unable to allocate statement handle"_L1, d); return false; } } else { r = SQLFreeStmt(d->hStmt, SQL_CLOSE); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QDB2Result::reset: Unable to close statement handle"), d); + qSqlWarning("QDB2Result::reset: Unable to close statement handle"_L1, d); return false; } } @@ -581,8 +583,8 @@ static bool qMakeStatement(QDB2ResultPrivate* d, bool forwardOnly, bool setForwa } if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { qSqlWarning(QString::fromLatin1("QDB2Result::reset: Unable to set %1 attribute.").arg( - forwardOnly ? QLatin1String("SQL_CURSOR_FORWARD_ONLY") - : QLatin1String("SQL_CURSOR_STATIC")), d); + forwardOnly ? "SQL_CURSOR_FORWARD_ONLY"_L1 + : "SQL_CURSOR_STATIC"_L1), d); return false; } return true; @@ -607,8 +609,7 @@ QDB2Result::~QDB2Result() if (d->hStmt) { SQLRETURN r = SQLFreeHandle(SQL_HANDLE_STMT, d->hStmt); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver: Unable to free statement handle ") - + QString::number(r), d); + qSqlWarning("QDB2Driver: Unable to free statement handle "_L1 + QString::number(r), d); } } @@ -1159,7 +1160,7 @@ int QDB2Result::numRowsAffected() if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) return affectedRowCount; else - qSqlWarning(QLatin1String("QDB2Result::numRowsAffected: Unable to count affected rows"), d); + qSqlWarning("QDB2Result::numRowsAffected: Unable to count affected rows"_L1, d); return -1; } @@ -1254,7 +1255,7 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas SQL_NULL_HANDLE, &d->hEnv); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { - qSqlWarning(QLatin1String("QDB2Driver::open: Unable to allocate environment"), d); + qSqlWarning("QDB2Driver::open: Unable to allocate environment"_L1, d); setOpenError(true); return false; } @@ -1263,7 +1264,7 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas d->hEnv, &d->hDbc); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { - qSqlWarning(QLatin1String("QDB2Driver::open: Unable to allocate connection"), d); + qSqlWarning("QDB2Driver::open: Unable to allocate connection"_L1, d); setOpenError(true); return false; } @@ -1285,10 +1286,10 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas SQLULEN v = 0; r = SQL_SUCCESS; - if (opt == QLatin1String("SQL_ATTR_ACCESS_MODE")) { - if (val == QLatin1String("SQL_MODE_READ_ONLY")) { + if (opt == "SQL_ATTR_ACCESS_MODE"_L1) { + if (val == "SQL_MODE_READ_ONLY"_L1) { v = SQL_MODE_READ_ONLY; - } else if (val == QLatin1String("SQL_MODE_READ_WRITE")) { + } else if (val == "SQL_MODE_READ_WRITE"_L1) { v = SQL_MODE_READ_WRITE; } else { qWarning("QDB2Driver::open: Unknown option value '%s'", @@ -1296,10 +1297,10 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas continue; } r = SQLSetConnectAttr(d->hDbc, SQL_ATTR_ACCESS_MODE, reinterpret_cast<SQLPOINTER>(v), 0); - } else if (opt == QLatin1String("SQL_ATTR_LOGIN_TIMEOUT")) { + } else if (opt == "SQL_ATTR_LOGIN_TIMEOUT"_L1) { v = val.toUInt(); r = SQLSetConnectAttr(d->hDbc, SQL_ATTR_LOGIN_TIMEOUT, reinterpret_cast<SQLPOINTER>(v), 0); - } else if (opt.compare(QLatin1String("PROTOCOL"), Qt::CaseInsensitive) == 0) { + } else if (opt.compare("PROTOCOL"_L1, Qt::CaseInsensitive) == 0) { protocol = tmp; } else { @@ -1312,15 +1313,15 @@ bool QDB2Driver::open(const QString& db, const QString& user, const QString& pas } if (protocol.isEmpty()) - protocol = QLatin1String("PROTOCOL=TCPIP"); + protocol = "PROTOCOL=TCPIP"_L1; if (port < 0 ) port = 50000; QString connQStr; - connQStr = protocol + QLatin1String(";DATABASE=") + db + QLatin1String(";HOSTNAME=") + host - + QLatin1String(";PORT=") + QString::number(port) + QLatin1String(";UID=") + user - + QLatin1String(";PWD=") + password; + connQStr = protocol + ";DATABASE="_L1 + db + ";HOSTNAME="_L1 + host + + ";PORT="_L1 + QString::number(port) + ";UID="_L1 + user + + ";PWD="_L1 + password; SQLTCHAR connOut[SQL_MAX_OPTION_STRING_LENGTH]; @@ -1356,18 +1357,18 @@ void QDB2Driver::close() if (isOpen()) { r = SQLDisconnect(d->hDbc); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver::close: Unable to disconnect datasource"), d); + qSqlWarning("QDB2Driver::close: Unable to disconnect datasource"_L1, d); } r = SQLFreeHandle(SQL_HANDLE_DBC, d->hDbc); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver::close: Unable to free connection handle"), d); + qSqlWarning("QDB2Driver::close: Unable to free connection handle"_L1, d); d->hDbc = 0; } if (d->hEnv) { r = SQLFreeHandle(SQL_HANDLE_ENV, d->hEnv); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver::close: Unable to free environment handle"), d); + qSqlWarning("QDB2Driver::close: Unable to free environment handle"_L1, d); d->hEnv = 0; } setOpen(false); @@ -1411,7 +1412,7 @@ QSqlRecord QDB2Driver::record(const QString& tableName) const d->hDbc, &hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QDB2Driver::record: Unable to allocate handle"), d); + qSqlWarning("QDB2Driver::record: Unable to allocate handle"_L1, d); return fil; } @@ -1434,7 +1435,7 @@ QSqlRecord QDB2Driver::record(const QString& tableName) const 0); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver::record: Unable to execute column list"), d); + qSqlWarning("QDB2Driver::record: Unable to execute column list"_L1, d); r = SQLFetchScroll(hStmt, SQL_FETCH_NEXT, 0); @@ -1449,7 +1450,7 @@ QSqlRecord QDB2Driver::record(const QString& tableName) const r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver: Unable to free statement handle ") + qSqlWarning("QDB2Driver: Unable to free statement handle "_L1 + QString::number(r), d); return fil; @@ -1468,7 +1469,7 @@ QStringList QDB2Driver::tables(QSql::TableType type) const d->hDbc, &hStmt); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { - qSqlWarning(QLatin1String("QDB2Driver::tables: Unable to allocate handle"), d); + qSqlWarning("QDB2Driver::tables: Unable to allocate handle"_L1, d); return tl; } r = SQLSetStmtAttr(hStmt, @@ -1478,11 +1479,11 @@ QStringList QDB2Driver::tables(QSql::TableType type) const QString tableType; if (type & QSql::Tables) - tableType += QLatin1String("TABLE,"); + tableType += "TABLE,"_L1; if (type & QSql::Views) - tableType += QLatin1String("VIEW,"); + tableType += "VIEW,"_L1; if (type & QSql::SystemTables) - tableType += QLatin1String("SYSTEM TABLE,"); + tableType += "SYSTEM TABLE,"_L1; if (tableType.isEmpty()) return tl; tableType.chop(1); @@ -1498,7 +1499,7 @@ QStringList QDB2Driver::tables(QSql::TableType type) const tableType.length()); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) - qSqlWarning(QLatin1String("QDB2Driver::tables: Unable to execute table list"), d); + qSqlWarning("QDB2Driver::tables: Unable to execute table list"_L1, d); r = SQLFetchScroll(hStmt, SQL_FETCH_NEXT, 0); @@ -1522,7 +1523,7 @@ QStringList QDB2Driver::tables(QSql::TableType type) const r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver::tables: Unable to free statement handle ") + qSqlWarning("QDB2Driver::tables: Unable to free statement handle "_L1 + QString::number(r), d); return tl; } @@ -1540,7 +1541,7 @@ QSqlIndex QDB2Driver::primaryIndex(const QString& tablename) const d->hDbc, &hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QDB2Driver::primaryIndex: Unable to list primary key"), d); + qSqlWarning("QDB2Driver::primaryIndex: Unable to list primary key"_L1, d); return index; } QString catalog, schema, table; @@ -1591,7 +1592,7 @@ QSqlIndex QDB2Driver::primaryIndex(const QString& tablename) const } r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r!= SQL_SUCCESS) - qSqlWarning(QLatin1String("QDB2Driver: Unable to free statement handle ") + qSqlWarning("QDB2Driver: Unable to free statement handle "_L1 + QString::number(r), d); return index; } @@ -1685,7 +1686,7 @@ bool QDB2Driver::setAutoCommit(bool autoCommit) QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const { if (field.isNull()) - return QLatin1String("NULL"); + return "NULL"_L1; switch (field.metaType().id()) { case QMetaType::QDateTime: { @@ -1705,20 +1706,20 @@ QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const + QString::number(tm.msec() * 1000).rightJustified(6, u'0', true) + u'\''; } else { - return QLatin1String("NULL"); + return "NULL"_L1; } } case QMetaType::QByteArray: { QByteArray ba = field.value().toByteArray(); QString res; - res += QLatin1String("BLOB(X'"); + res += "BLOB(X'"_L1; static const char hexchars[] = "0123456789abcdef"; for (int i = 0; i < ba.size(); ++i) { uchar s = (uchar) ba[i]; res += QLatin1Char(hexchars[s >> 4]); res += QLatin1Char(hexchars[s & 0x0f]); } - res += QLatin1String("')"); + res += "')"_L1; return res; } default: @@ -1736,9 +1737,9 @@ QString QDB2Driver::escapeIdentifier(const QString &identifier, IdentifierType) { QString res = identifier; if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) { - res.replace(u'"', QLatin1String("\"\"")); + res.replace(u'"', "\"\""_L1); res.prepend(u'"').append(u'"'); - res.replace(u'.', QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } diff --git a/src/plugins/sqldrivers/ibase/main.cpp b/src/plugins/sqldrivers/ibase/main.cpp index 9f34899d8c..835186d535 100644 --- a/src/plugins/sqldrivers/ibase/main.cpp +++ b/src/plugins/sqldrivers/ibase/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QIBaseDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QIBaseDriverPlugin::QIBaseDriverPlugin() QSqlDriver* QIBaseDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QIBASE")) { + if (name == "QIBASE"_L1) { QIBaseDriver* driver = new QIBaseDriver(); return driver; } diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index 65ee4f7290..fda95c283b 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -59,6 +59,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #define FBVERSION SQL_DIALECT_V6 #ifndef SQLDA_CURRENT_VERSION @@ -82,7 +84,7 @@ static bool getIBaseError(QString& msg, const ISC_STATUS* status, ISC_LONG &sqlc char buf[512]; while(fb_interpret(buf, 512, &status)) { if (!msg.isEmpty()) - msg += QLatin1String(" - "); + msg += " - "_L1; msg += QString::fromUtf8(buf); } return true; @@ -686,8 +688,8 @@ static char* createArrayBuffer(char *buffer, const QList<QVariant> &list, bounds[curDim].array_bound_lower + 1); if (list.size() != elements) { // size mismatch - error = QLatin1String("Expected size: %1. Supplied size: %2"); - error = QLatin1String("Array size mismatch. Fieldname: %1 ") + error = "Expected size: %1. Supplied size: %2"_L1; + error = "Array size mismatch. Fieldname: %1 "_L1 + error.arg(elements).arg(list.size()); return 0; } @@ -696,7 +698,7 @@ static char* createArrayBuffer(char *buffer, const QList<QVariant> &list, for(i = 0; i < list.size(); ++i) { if (list.at(i).typeId() != QMetaType::QVariantList) { // dimensions mismatch - error = QLatin1String("Array dimensons mismatch. Fieldname: %1"); + error = "Array dimensons mismatch. Fieldname: %1"_L1; return 0; } @@ -799,16 +801,16 @@ bool QIBaseResultPrivate::writeArray(int column, const QList<QVariant> &list) ba.resize(int(bufLen)); if (list.size() > arraySize) { - error = QLatin1String("Array size mismatch: size of %1 is %2, size of provided list is %3"); + 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()); - q->setLastError(QSqlError(error, QLatin1String(""), QSqlError::StatementError)); + q->setLastError(QSqlError(error, ""_L1, QSqlError::StatementError)); return false; } 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)), QLatin1String(""), + q->setLastError(QSqlError(error.arg(QLatin1String(sqlname)), ""_L1, QSqlError::StatementError)); return false; } @@ -972,9 +974,9 @@ bool QIBaseResult::exec() const QList<QVariant> &values = boundValues(); int i; if (values.count() > d->inda->sqld) { - qWarning() << QLatin1String("QIBaseResult::exec: Parameter mismatch, expected") << - d->inda->sqld << QLatin1String(", got") << values.count() << - QLatin1String("parameters"); + qWarning() << "QIBaseResult::exec: Parameter mismatch, expected"_L1 << + d->inda->sqld << ", got"_L1 << values.count() << + "parameters"_L1; return false; } int para = 0; @@ -1370,11 +1372,11 @@ QSqlRecord QIBaseResult::record() const if (v.sqlscale < 0) { QSqlQuery q(driver()->createResult()); q.setForwardOnly(true); - q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG " + q.exec("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG " "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " - "AND a.RDB$RELATION_NAME = '") + QString::fromLatin1(v.relname, v.relname_length) + QLatin1String("' " - "AND a.RDB$FIELD_NAME = '") + QString::fromLatin1(v.sqlname, v.sqlname_length) + QLatin1String("' ")); + "AND a.RDB$RELATION_NAME = '"_L1 + QString::fromLatin1(v.relname, v.relname_length) + "' " + "AND a.RDB$FIELD_NAME = '"_L1 + QString::fromLatin1(v.sqlname, v.sqlname_length) + "' "_L1); if (q.first()) { if (v.sqlscale < 0) { f.setLength(q.value(0).toInt()); @@ -1462,7 +1464,7 @@ bool QIBaseDriver::open(const QString & db, if ((idx = tmp.indexOf(u'=')) != -1) { QString val = tmp.mid(idx + 1).simplified(); QString opt = tmp.left(idx).simplified(); - if (opt.toUpper() == QLatin1String("ISC_DPB_SQL_ROLE_NAME")) { + if (opt.toUpper() == "ISC_DPB_SQL_ROLE_NAME"_L1) { role = val.toLocal8Bit(); role.truncate(255); } @@ -1601,25 +1603,25 @@ QStringList QIBaseDriver::tables(QSql::TableType type) const QString typeFilter; if (type == QSql::SystemTables) { - typeFilter += QLatin1String("RDB$SYSTEM_FLAG != 0"); + typeFilter += "RDB$SYSTEM_FLAG != 0"_L1; } else if (type == (QSql::SystemTables | QSql::Views)) { - typeFilter += QLatin1String("RDB$SYSTEM_FLAG != 0 OR RDB$VIEW_BLR NOT NULL"); + typeFilter += "RDB$SYSTEM_FLAG != 0 OR RDB$VIEW_BLR NOT NULL"_L1; } else { if (!(type & QSql::SystemTables)) - typeFilter += QLatin1String("RDB$SYSTEM_FLAG = 0 AND "); + typeFilter += "RDB$SYSTEM_FLAG = 0 AND "_L1; if (!(type & QSql::Views)) - typeFilter += QLatin1String("RDB$VIEW_BLR IS NULL AND "); + typeFilter += "RDB$VIEW_BLR IS NULL AND "_L1; if (!(type & QSql::Tables)) - typeFilter += QLatin1String("RDB$VIEW_BLR IS NOT NULL AND "); + typeFilter += "RDB$VIEW_BLR IS NOT NULL AND "_L1; if (!typeFilter.isEmpty()) typeFilter.chop(5); } if (!typeFilter.isEmpty()) - typeFilter.prepend(QLatin1String("where ")); + typeFilter.prepend("where "_L1); QSqlQuery q(createResult()); q.setForwardOnly(true); - if (!q.exec(QLatin1String("select rdb$relation_name from rdb$relations ") + typeFilter)) + if (!q.exec("select rdb$relation_name from rdb$relations "_L1 + typeFilter)) return res; while(q.next()) res << q.value(0).toString().simplified(); @@ -1640,12 +1642,12 @@ QSqlRecord QIBaseDriver::record(const QString& tablename) const table = stripDelimiters(table, QSqlDriver::TableName); else table = table.toUpper(); - q.exec(QLatin1String("SELECT a.RDB$FIELD_NAME, b.RDB$FIELD_TYPE, b.RDB$FIELD_LENGTH, " + q.exec("SELECT a.RDB$FIELD_NAME, b.RDB$FIELD_TYPE, b.RDB$FIELD_LENGTH, " "b.RDB$FIELD_SCALE, b.RDB$FIELD_PRECISION, a.RDB$NULL_FLAG " "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b " "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE " - "AND a.RDB$RELATION_NAME = '") + table + QLatin1String("' " - "ORDER BY a.RDB$FIELD_POSITION")); + "AND a.RDB$RELATION_NAME = '"_L1 + table + "' " + "ORDER BY a.RDB$FIELD_POSITION"_L1); while (q.next()) { int type = q.value(1).toInt(); @@ -1680,15 +1682,15 @@ QSqlIndex QIBaseDriver::primaryIndex(const QString &table) const QSqlQuery q(createResult()); q.setForwardOnly(true); - q.exec(QLatin1String("SELECT a.RDB$INDEX_NAME, b.RDB$FIELD_NAME, d.RDB$FIELD_TYPE, d.RDB$FIELD_SCALE " + q.exec("SELECT a.RDB$INDEX_NAME, b.RDB$FIELD_NAME, d.RDB$FIELD_TYPE, d.RDB$FIELD_SCALE " "FROM RDB$RELATION_CONSTRAINTS a, RDB$INDEX_SEGMENTS b, RDB$RELATION_FIELDS c, RDB$FIELDS d " "WHERE a.RDB$CONSTRAINT_TYPE = 'PRIMARY KEY' " - "AND a.RDB$RELATION_NAME = '") + tablename + - QLatin1String(" 'AND a.RDB$INDEX_NAME = b.RDB$INDEX_NAME " + "AND a.RDB$RELATION_NAME = '"_L1 + tablename + + " 'AND a.RDB$INDEX_NAME = b.RDB$INDEX_NAME " "AND c.RDB$RELATION_NAME = a.RDB$RELATION_NAME " "AND c.RDB$FIELD_NAME = b.RDB$FIELD_NAME " "AND d.RDB$FIELD_NAME = c.RDB$FIELD_SOURCE " - "ORDER BY b.RDB$FIELD_POSITION")); + "ORDER BY b.RDB$FIELD_POSITION"_L1); while (q.next()) { QSqlField field(q.value(1).toString().simplified(), @@ -1716,7 +1718,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons QString::number(datetime.time().msec()).rightJustified(3, u'0', true) + u'\''; else - return QLatin1String("NULL"); + return "NULL"_L1; } case QMetaType::QTime: { QTime time = field.value().toTime(); @@ -1727,7 +1729,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons QString::number(time.msec()).rightJustified(3, u'0', true) + u'\''; else - return QLatin1String("NULL"); + return "NULL"_L1; } case QMetaType::QDate: { QDate date = field.value().toDate(); @@ -1736,7 +1738,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons QString::number(date.month()) + u'-' + QString::number(date.day()) + u'\''; else - return QLatin1String("NULL"); + return "NULL"_L1; } default: return QSqlDriver::formatValue(field, trimStrings); @@ -1893,9 +1895,9 @@ QString QIBaseDriver::escapeIdentifier(const QString &identifier, IdentifierType { QString res = identifier; if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) { - res.replace(u'"', QLatin1String("\"\"")); + res.replace(u'"', "\"\""_L1); res.prepend(u'"').append(u'"'); - res.replace(u'.', QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } diff --git a/src/plugins/sqldrivers/mysql/main.cpp b/src/plugins/sqldrivers/mysql/main.cpp index f7d56dd1c9..bdf08fa044 100644 --- a/src/plugins/sqldrivers/mysql/main.cpp +++ b/src/plugins/sqldrivers/mysql/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QMYSQLDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,8 +63,7 @@ QMYSQLDriverPlugin::QMYSQLDriverPlugin() QSqlDriver* QMYSQLDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QMYSQL") || - name == QLatin1String("QMARIADB")) { + if (name == "QMYSQL"_L1 || name == "QMARIADB"_L1) { QMYSQLDriver* driver = new QMYSQLDriver(); return driver; } diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 5fd8356834..b8dd32790f 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -71,6 +71,8 @@ using my_bool = decltype(mysql_stmt_bind_result(nullptr, nullptr)); QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QMYSQLDriverPrivate : public QSqlDriverPrivate { Q_DECLARE_PUBLIC(QMYSQLDriver) @@ -209,7 +211,7 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, const QMYSQLDriverPrivate* p) { const char *cerr = p->mysql ? mysql_error(p->mysql) : 0; - return QSqlError(QLatin1String("QMYSQL: ") + err, + return QSqlError("QMYSQL: "_L1 + err, QString::fromUtf8(cerr), type, QString::number(mysql_errno(p->mysql))); } @@ -290,7 +292,7 @@ static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type, MYSQL_STMT* stmt) { const char *cerr = mysql_stmt_error(stmt); - return QSqlError(QLatin1String("QMYSQL: ") + err, + return QSqlError("QMYSQL: "_L1 + err, QString::fromLatin1(cerr), type, QString::number(mysql_stmt_errno(stmt))); } @@ -1168,19 +1170,19 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const static void setOptionFlag(uint &optionFlags, const QString &opt) { - if (opt == QLatin1String("CLIENT_COMPRESS")) + if (opt == "CLIENT_COMPRESS"_L1) optionFlags |= CLIENT_COMPRESS; - else if (opt == QLatin1String("CLIENT_FOUND_ROWS")) + else if (opt == "CLIENT_FOUND_ROWS"_L1) optionFlags |= CLIENT_FOUND_ROWS; - else if (opt == QLatin1String("CLIENT_IGNORE_SPACE")) + else if (opt == "CLIENT_IGNORE_SPACE"_L1) optionFlags |= CLIENT_IGNORE_SPACE; - else if (opt == QLatin1String("CLIENT_INTERACTIVE")) + else if (opt == "CLIENT_INTERACTIVE"_L1) optionFlags |= CLIENT_INTERACTIVE; - else if (opt == QLatin1String("CLIENT_NO_SCHEMA")) + else if (opt == "CLIENT_NO_SCHEMA"_L1) optionFlags |= CLIENT_NO_SCHEMA; - else if (opt == QLatin1String("CLIENT_ODBC")) + else if (opt == "CLIENT_ODBC"_L1) optionFlags |= CLIENT_ODBC; - else if (opt == QLatin1String("CLIENT_SSL")) + else if (opt == "CLIENT_SSL"_L1) qWarning("QMYSQLDriver: SSL_KEY, SSL_CERT and SSL_CA should be used instead of CLIENT_SSL."); else qWarning("QMYSQLDriver::open: Unknown connect option '%s'", opt.toLocal8Bit().constData()); @@ -1222,28 +1224,28 @@ bool QMYSQLDriver::open(const QString& db, if ((idx = tmp.indexOf(u'=')) != -1) { QString val = tmp.mid(idx + 1).simplified(); QString opt = tmp.left(idx).simplified(); - if (opt == QLatin1String("UNIX_SOCKET")) + if (opt == "UNIX_SOCKET"_L1) unixSocket = val; - else if (opt == QLatin1String("MYSQL_OPT_RECONNECT")) { - if (val == QLatin1String("TRUE") || val == QLatin1String("1") || val.isEmpty()) + else if (opt == "MYSQL_OPT_RECONNECT"_L1) { + if (val == "TRUE"_L1 || val == "1"_L1 || val.isEmpty()) reconnect = true; - } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) + } else if (opt == "MYSQL_OPT_CONNECT_TIMEOUT"_L1) connectTimeout = val.toInt(); - else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) + else if (opt == "MYSQL_OPT_READ_TIMEOUT"_L1) readTimeout = val.toInt(); - else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) + else if (opt == "MYSQL_OPT_WRITE_TIMEOUT"_L1) writeTimeout = val.toInt(); - else if (opt == QLatin1String("SSL_KEY")) + else if (opt == "SSL_KEY"_L1) sslKey = val; - else if (opt == QLatin1String("SSL_CERT")) + else if (opt == "SSL_CERT"_L1) sslCert = val; - else if (opt == QLatin1String("SSL_CA")) + else if (opt == "SSL_CA"_L1) sslCA = val; - else if (opt == QLatin1String("SSL_CAPATH")) + else if (opt == "SSL_CAPATH"_L1) sslCAPath = val; - else if (opt == QLatin1String("SSL_CIPHER")) + else if (opt == "SSL_CIPHER"_L1) sslCipher = val; - else if (val == QLatin1String("TRUE") || val == QLatin1String("1")) + else if (val == "TRUE"_L1 || val == "1"_L1) setOptionFlag(optionFlags, tmp.left(idx).simplified()); else qWarning("QMYSQLDriver::open: Illegal connect option value '%s'", @@ -1374,14 +1376,14 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const QStringList tl; QSqlQuery q(createResult()); if (type & QSql::Tables) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); + QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1String(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 = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); + QString sql = "select table_name from information_schema.tables where table_schema = '"_L1 + QLatin1String(d->mysql->db) + "' and table_type = 'VIEW'"_L1; q.exec(sql); while (q.next()) @@ -1397,11 +1399,11 @@ QSqlIndex QMYSQLDriver::primaryIndex(const QString& tablename) const return idx; QSqlQuery i(createResult()); - QString stmt(QLatin1String("show index from %1;")); + QString stmt("show index from %1;"_L1); QSqlRecord fil = record(tablename); i.exec(stmt.arg(escapeIdentifier(tablename, QSqlDriver::TableName))); while (i.isActive() && i.next()) { - if (i.value(2).toString() == QLatin1String("PRIMARY")) { + if (i.value(2).toString() == "PRIMARY"_L1) { idx.append(fil.field(i.value(4).toString())); idx.setCursorName(i.value(0).toString()); idx.setName(i.value(2).toString()); @@ -1498,7 +1500,7 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons case QMetaType::QString: // Escape '\' characters r = QSqlDriver::formatValue(field, trimStrings); - r.replace(QLatin1String("\\"), QLatin1String("\\\\")); + r.replace("\\"_L1, "\\\\"_L1); break; case QMetaType::QByteArray: if (isOpen()) { @@ -1539,7 +1541,7 @@ QString QMYSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType QString res = identifier; if (!identifier.isEmpty() && !identifier.startsWith(u'`') && !identifier.endsWith(u'`') ) { res.prepend(u'`').append(u'`'); - res.replace(u'.', QLatin1String("`.`")); + res.replace(u'.', "`.`"_L1); } return res; } diff --git a/src/plugins/sqldrivers/oci/main.cpp b/src/plugins/sqldrivers/oci/main.cpp index db273bfb04..9b80bd940d 100644 --- a/src/plugins/sqldrivers/oci/main.cpp +++ b/src/plugins/sqldrivers/oci/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QOCIDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QOCIDriverPlugin::QOCIDriverPlugin() QSqlDriver* QOCIDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QOCI")) { + if (name == "QOCI"_L1) { QOCIDriver* driver = new QOCIDriver(); return driver; } diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index 01fdc4adc5..8638a070cc 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -92,6 +92,8 @@ Q_DECLARE_METATYPE(OCIStmt*) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN enum { QOCIEncoding = 2002 }; // AL16UTF16LE #else @@ -654,15 +656,15 @@ QSqlError qMakeError(const QString& errString, QSqlError::ErrorType type, OCIErr QMetaType qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy precisionPolicy) { int type = QMetaType::UnknownType; - if (ocitype == QLatin1String("VARCHAR2") || ocitype == QLatin1String("VARCHAR") - || ocitype.startsWith(QLatin1String("INTERVAL")) - || ocitype == QLatin1String("CHAR") || ocitype == QLatin1String("NVARCHAR2") - || ocitype == QLatin1String("NCHAR")) + if (ocitype == "VARCHAR2"_L1 || ocitype == "VARCHAR"_L1 + || ocitype.startsWith("INTERVAL"_L1) + || ocitype == "CHAR"_L1 || ocitype == "NVARCHAR2"_L1 + || ocitype == "NCHAR"_L1) type = QMetaType::QString; - else if (ocitype == QLatin1String("NUMBER") - || ocitype == QLatin1String("FLOAT") - || ocitype == QLatin1String("BINARY_FLOAT") - || ocitype == QLatin1String("BINARY_DOUBLE")) { + else if (ocitype == "NUMBER"_L1 + || ocitype == "FLOAT"_L1 + || ocitype == "BINARY_FLOAT"_L1 + || ocitype == "BINARY_DOUBLE"_L1) { switch(precisionPolicy) { case QSql::LowPrecisionInt32: type = QMetaType::Int; @@ -679,16 +681,15 @@ QMetaType qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy break; } } - else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB") - || ocitype == QLatin1String("CLOB")) + else if (ocitype == "LONG"_L1 || ocitype == "NCLOB"_L1 || ocitype == "CLOB"_L1) type = QMetaType::QByteArray; - else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW") - || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB") - || ocitype == QLatin1String("CFILE") || ocitype == QLatin1String("BFILE")) + else if (ocitype == "RAW"_L1 || ocitype == "LONG RAW"_L1 + || ocitype == "ROWID"_L1 || ocitype == "BLOB"_L1 + || ocitype == "CFILE"_L1 || ocitype == "BFILE"_L1) type = QMetaType::QByteArray; - else if (ocitype == QLatin1String("DATE") || ocitype.startsWith(QLatin1String("TIME"))) + else if (ocitype == "DATE"_L1 || ocitype.startsWith("TIME"_L1)) type = QMetaType::QDateTime; - else if (ocitype == QLatin1String("UNDEFINED")) + else if (ocitype == "UNDEFINED"_L1) type = QMetaType::UnknownType; if (type == QMetaType::UnknownType) qWarning("qDecodeOCIType: unknown type: %s", ocitype.toLocal8Bit().constData()); @@ -2237,11 +2238,11 @@ static void qParseOpts(const QString &options, QOCIDriverPrivate *d) const QString opt = tmp.left(idx); const QString val = tmp.mid(idx + 1).simplified(); bool ok; - if (opt == QLatin1String("OCI_ATTR_PREFETCH_ROWS")) { + if (opt == "OCI_ATTR_PREFETCH_ROWS"_L1) { d->prefetchRows = val.toInt(&ok); if (!ok) d->prefetchRows = -1; - } else if (opt == QLatin1String("OCI_ATTR_PREFETCH_MEMORY")) { + } else if (opt == "OCI_ATTR_PREFETCH_MEMORY"_L1) { d->prefetchMem = val.toInt(&ok); if (!ok) d->prefetchMem = -1; @@ -2349,7 +2350,7 @@ bool QOCIDriver::open(const QString & db, QString versionStr; versionStr = QString(reinterpret_cast<const QChar *>(vertxt)); #if QT_CONFIG(regularexpression) - auto match = QRegularExpression(QLatin1String("([0-9]+)\\.[0-9\\.]+[0-9]")).match(versionStr); + auto match = QRegularExpression("([0-9]+)\\.[0-9\\.]+[0-9]"_L1).match(versionStr); if (match.hasMatch()) d->serverVersion = match.captured(1).toInt(); #endif @@ -2478,7 +2479,7 @@ static QString make_where_clause(const QString &user, Expression e) for (const auto &sysUser : sysUsers) { const QLatin1String l1(sysUser); if (l1 != user) - result += QLatin1String("owner ") + bang[e] + QLatin1String("= '") + l1 + QLatin1String("' ") + join + u' '; + result += "owner "_L1 + bang[e] + "= '"_L1 + l1 + "' "_L1 + join + u' '; } result.chop(join.size() + 2); // remove final " <join> " @@ -2503,7 +2504,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const QSqlQuery t(createResult()); t.setForwardOnly(true); if (type & QSql::Tables) { - const QLatin1String tableQuery("select owner, table_name from all_tables where "); + const auto tableQuery = "select owner, table_name from all_tables where "_L1; const QString where = make_where_clause(user, AndExpression); t.exec(tableQuery + where); while (t.next()) { @@ -2514,7 +2515,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const } // list all table synonyms as well - const QLatin1String synonymQuery("select owner, synonym_name from all_synonyms where "); + const auto synonymQuery = "select owner, synonym_name from all_synonyms where "_L1; t.exec(synonymQuery + where); while (t.next()) { if (t.value(0).toString() != d->user) @@ -2524,7 +2525,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const } } if (type & QSql::Views) { - const QLatin1String query("select owner, view_name from all_views where "); + const auto query = "select owner, view_name from all_views where "_L1; const QString where = make_where_clause(user, AndExpression); t.exec(query + where); while (t.next()) { @@ -2535,11 +2536,11 @@ QStringList QOCIDriver::tables(QSql::TableType type) const } } if (type & QSql::SystemTables) { - t.exec(QLatin1String("select table_name from dictionary")); + t.exec("select table_name from dictionary"_L1); while (t.next()) { tl.append(t.value(0).toString()); } - const QLatin1String tableQuery("select owner, table_name from all_tables where "); + const auto tableQuery = "select owner, table_name from all_tables where "_L1; const QString where = make_where_clause(user, OrExpression); t.exec(tableQuery + where); while (t.next()) { @@ -2550,7 +2551,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const } // list all table synonyms as well - const QLatin1String synonymQuery("select owner, synonym_name from all_synonyms where "); + const auto synonymQuery = "select owner, synonym_name from all_synonyms where "_L1; t.exec(synonymQuery + where); while (t.next()) { if (t.value(0).toString() != d->user) @@ -2584,14 +2585,14 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const QSqlQuery t(createResult()); // using two separate queries for this is A LOT faster than using // eg. a sub-query on the sys.synonyms table - QString stmt(QLatin1String("select column_name, data_type, data_length, " + QString stmt("select column_name, data_type, data_length, " "data_precision, data_scale, nullable, data_default%1" "from all_tab_columns a " - "where a.table_name=%2")); + "where a.table_name=%2"_L1); if (d->serverVersion >= 9) - stmt = stmt.arg(QLatin1String(", char_length ")); + stmt = stmt.arg(", char_length "_L1); else - stmt = stmt.arg(QLatin1String(" ")); + stmt = stmt.arg(" "_L1); bool buildRecordInfo = false; QString table, owner, tmpStmt; qSplitTableAndOwner(tablename, &table, &owner); @@ -2611,14 +2612,12 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const else owner = owner.toUpper(); - tmpStmt += QLatin1String(" and a.owner='") + owner + u'\''; + tmpStmt += " and a.owner='"_L1 + owner + u'\''; t.setForwardOnly(true); t.exec(tmpStmt); if (!t.next()) { // try and see if the tablename is a synonym - stmt = stmt + QLatin1String(" join all_synonyms b " - "on a.owner=b.table_owner and a.table_name=b.table_name " - "where b.owner='") + owner + - QLatin1String("' and b.synonym_name='") + table + u'\''; + stmt = stmt + " join all_synonyms b on a.owner=b.table_owner and a.table_name=b.table_name " + "where b.owner='"_L1 + owner + "' and b.synonym_name='"_L1 + table + u'\''; t.setForwardOnly(true); t.exec(stmt); if (t.next()) @@ -2626,13 +2625,13 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const } else { buildRecordInfo = true; } - QStringList keywords = QStringList() << QLatin1String("NUMBER") << QLatin1String("FLOAT") << QLatin1String("BINARY_FLOAT") - << QLatin1String("BINARY_DOUBLE"); + QStringList keywords = QStringList() << "NUMBER"_L1 << "FLOAT"_L1 << "BINARY_FLOAT"_L1 + << "BINARY_DOUBLE"_L1; if (buildRecordInfo) { do { QMetaType ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy()); QSqlField f(t.value(0).toString(), ty); - f.setRequired(t.value(5).toString() == QLatin1String("N")); + f.setRequired(t.value(5).toString() == "N"_L1); f.setPrecision(t.value(4).toInt()); if (d->serverVersion >= 9 && (ty.id() == QMetaType::QString) && !t.isNull(3) && !keywords.contains(t.value(1).toString())) { // Oracle9: data_length == size in bytes, char_length == amount of characters @@ -2654,11 +2653,11 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const if (!isOpen()) return idx; QSqlQuery t(createResult()); - QString stmt(QLatin1String("select b.column_name, b.index_name, a.table_name, a.owner " + QString stmt("select b.column_name, b.index_name, a.table_name, a.owner " "from all_constraints a, all_ind_columns b " "where a.constraint_type='P' " "and b.index_name = a.index_name " - "and b.index_owner = a.owner")); + "and b.index_owner = a.owner"_L1); bool buildIndex = false; QString table, owner, tmpStmt; @@ -2669,7 +2668,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const else table = table.toUpper(); - tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + u'\''; + tmpStmt = stmt + " and a.table_name='"_L1 + table + u'\''; if (owner.isEmpty()) { owner = d->user; } @@ -2679,13 +2678,13 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const else owner = owner.toUpper(); - tmpStmt += QLatin1String(" and a.owner='") + owner + u'\''; + tmpStmt += " and a.owner='"_L1 + owner + u'\''; t.setForwardOnly(true); t.exec(tmpStmt); if (!t.next()) { - stmt += QLatin1String(" and a.table_name=(select tname from sys.synonyms " - "where sname='") + table + QLatin1String("' and creator=a.owner)"); + stmt += " and a.table_name=(select tname from sys.synonyms where sname='"_L1 + + table + "' and creator=a.owner)"_L1; t.setForwardOnly(true); t.exec(stmt); if (t.next()) { @@ -2700,9 +2699,9 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const tt.setForwardOnly(true); idx.setName(t.value(1).toString()); do { - tt.exec(QLatin1String("select data_type from all_tab_columns where table_name='") + - t.value(2).toString() + QLatin1String("' and column_name='") + - t.value(0).toString() + QLatin1String("' and owner='") + + tt.exec("select data_type from all_tab_columns where table_name='"_L1 + + t.value(2).toString() + "' and column_name='"_L1 + + t.value(0).toString() + "' and owner='"_L1 + owner + u'\''); if (!tt.next()) { return QSqlIndex(); @@ -2722,16 +2721,16 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const QDateTime datetime = field.value().toDateTime(); QString datestring; if (datetime.isValid()) { - datestring = QLatin1String("TO_DATE('") + QString::number(datetime.date().year()) + datestring = "TO_DATE('"_L1 + QString::number(datetime.date().year()) + u'-' + QString::number(datetime.date().month()) + u'-' + QString::number(datetime.date().day()) + u' ' + QString::number(datetime.time().hour()) + u':' + QString::number(datetime.time().minute()) + u':' + QString::number(datetime.time().second()) - + QLatin1String("','YYYY-MM-DD HH24:MI:SS')"); + + "','YYYY-MM-DD HH24:MI:SS')"_L1; } else { - datestring = QLatin1String("NULL"); + datestring = "NULL"_L1; } return datestring; } @@ -2739,13 +2738,13 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const QDateTime datetime = field.value().toDateTime(); QString datestring; if (datetime.isValid()) { - datestring = QLatin1String("TO_DATE('") + datestring = "TO_DATE('"_L1 + QString::number(datetime.time().hour()) + u':' + QString::number(datetime.time().minute()) + u':' + QString::number(datetime.time().second()) - + QLatin1String("','HH24:MI:SS')"); + + "','HH24:MI:SS')"_L1; } else { - datestring = QLatin1String("NULL"); + datestring = "NULL"_L1; } return datestring; } @@ -2753,12 +2752,12 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const QDate date = field.value().toDate(); QString datestring; if (date.isValid()) { - datestring = QLatin1String("TO_DATE('") + QString::number(date.year()) + + datestring = "TO_DATE('"_L1 + QString::number(date.year()) + u'-' + QString::number(date.month()) + u'-' + - QString::number(date.day()) + QLatin1String("','YYYY-MM-DD')"); + QString::number(date.day()) + "','YYYY-MM-DD')"_L1; } else { - datestring = QLatin1String("NULL"); + datestring = "NULL"_L1; } return datestring; } @@ -2778,9 +2777,9 @@ QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType t { QString res = identifier; if (!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) { - res.replace(u'"', QLatin1String("\"\"")); + res.replace(u'"', "\"\""_L1); res.prepend(u'"').append(u'"'); - res.replace(u'.', QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } diff --git a/src/plugins/sqldrivers/odbc/main.cpp b/src/plugins/sqldrivers/odbc/main.cpp index 92478ecbd1..716177ad0a 100644 --- a/src/plugins/sqldrivers/odbc/main.cpp +++ b/src/plugins/sqldrivers/odbc/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QODBCDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QODBCDriverPlugin::QODBCDriverPlugin() QSqlDriver* QODBCDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QODBC")) { + if (name == "QODBC"_L1) { QODBCDriver* driver = new QODBCDriver(); return driver; } diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index c0349ba2c1..0d7217caeb 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // undefine this to prevent initial check of the ODBC driver #define ODBC_CHECK_DRIVER @@ -328,7 +330,7 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, const { int nativeCode = -1; QString message = qODBCWarn(p, &nativeCode); - return QSqlError(QLatin1String("QODBC: ") + err, message, type, + return QSqlError("QODBC: "_L1 + err, message, type, nativeCode != -1 ? QString::number(nativeCode) : QString()); } @@ -337,7 +339,7 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, { int nativeCode = -1; QString message = qODBCWarn(p, &nativeCode); - return QSqlError(QLatin1String("QODBC: ") + err, message, type, + return QSqlError("QODBC: "_L1 + err, message, type, nativeCode != -1 ? QString::number(nativeCode) : QString()); } @@ -743,7 +745,7 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, int i, QString *errorMess static size_t qGetODBCVersion(const QString &connOpts) { - if (connOpts.contains(QLatin1String("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3"), Qt::CaseInsensitive)) + if (connOpts.contains("SQL_ATTR_ODBC_VERSION=SQL_OV_ODBC3"_L1, Qt::CaseInsensitive)) return SQL_OV_ODBC3; return SQL_OV_ODBC2; } @@ -785,82 +787,82 @@ bool QODBCDriverPrivate::setConnectionOptions(const QString& connOpts) SQLUINTEGER v = 0; r = SQL_SUCCESS; - if (opt.toUpper() == QLatin1String("SQL_ATTR_ACCESS_MODE")) { - if (val.toUpper() == QLatin1String("SQL_MODE_READ_ONLY")) { + if (opt.toUpper() == "SQL_ATTR_ACCESS_MODE"_L1) { + if (val.toUpper() == "SQL_MODE_READ_ONLY"_L1) { v = SQL_MODE_READ_ONLY; - } else if (val.toUpper() == QLatin1String("SQL_MODE_READ_WRITE")) { + } else if (val.toUpper() == "SQL_MODE_READ_WRITE"_L1) { v = SQL_MODE_READ_WRITE; } else { qWarning() << "QODBCDriver::open: Unknown option value '" << val << '\''; continue; } r = SQLSetConnectAttr(hDbc, SQL_ATTR_ACCESS_MODE, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_CONNECTION_TIMEOUT")) { + } else if (opt.toUpper() == "SQL_ATTR_CONNECTION_TIMEOUT"_L1) { v = val.toUInt(); r = SQLSetConnectAttr(hDbc, SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_LOGIN_TIMEOUT")) { + } else if (opt.toUpper() == "SQL_ATTR_LOGIN_TIMEOUT"_L1) { v = val.toUInt(); r = SQLSetConnectAttr(hDbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_CURRENT_CATALOG")) { + } else if (opt.toUpper() == "SQL_ATTR_CURRENT_CATALOG"_L1) { val.utf16(); // 0 terminate r = SQLSetConnectAttr(hDbc, SQL_ATTR_CURRENT_CATALOG, toSQLTCHAR(val).data(), SQLINTEGER(val.length() * sizeof(SQLTCHAR))); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_METADATA_ID")) { - if (val.toUpper() == QLatin1String("SQL_TRUE")) { + } else if (opt.toUpper() == "SQL_ATTR_METADATA_ID"_L1) { + if (val.toUpper() == "SQL_TRUE"_L1) { v = SQL_TRUE; - } else if (val.toUpper() == QLatin1String("SQL_FALSE")) { + } else if (val.toUpper() == "SQL_FALSE"_L1) { v = SQL_FALSE; } else { qWarning() << "QODBCDriver::open: Unknown option value '" << val << '\''; continue; } r = SQLSetConnectAttr(hDbc, SQL_ATTR_METADATA_ID, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_PACKET_SIZE")) { + } else if (opt.toUpper() == "SQL_ATTR_PACKET_SIZE"_L1) { v = val.toUInt(); r = SQLSetConnectAttr(hDbc, SQL_ATTR_PACKET_SIZE, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACEFILE")) { + } else if (opt.toUpper() == "SQL_ATTR_TRACEFILE"_L1) { val.utf16(); // 0 terminate r = SQLSetConnectAttr(hDbc, SQL_ATTR_TRACEFILE, toSQLTCHAR(val).data(), SQLINTEGER(val.length() * sizeof(SQLTCHAR))); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_TRACE")) { - if (val.toUpper() == QLatin1String("SQL_OPT_TRACE_OFF")) { + } else if (opt.toUpper() == "SQL_ATTR_TRACE"_L1) { + if (val.toUpper() == "SQL_OPT_TRACE_OFF"_L1) { v = SQL_OPT_TRACE_OFF; - } else if (val.toUpper() == QLatin1String("SQL_OPT_TRACE_ON")) { + } else if (val.toUpper() == "SQL_OPT_TRACE_ON"_L1) { v = SQL_OPT_TRACE_ON; } else { qWarning() << "QODBCDriver::open: Unknown option value '" << val << '\''; continue; } r = SQLSetConnectAttr(hDbc, SQL_ATTR_TRACE, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_CONNECTION_POOLING")) { - if (val == QLatin1String("SQL_CP_OFF")) + } else if (opt.toUpper() == "SQL_ATTR_CONNECTION_POOLING"_L1) { + if (val == "SQL_CP_OFF"_L1) v = SQL_CP_OFF; - else if (val.toUpper() == QLatin1String("SQL_CP_ONE_PER_DRIVER")) + else if (val.toUpper() == "SQL_CP_ONE_PER_DRIVER"_L1) v = SQL_CP_ONE_PER_DRIVER; - else if (val.toUpper() == QLatin1String("SQL_CP_ONE_PER_HENV")) + else if (val.toUpper() == "SQL_CP_ONE_PER_HENV"_L1) v = SQL_CP_ONE_PER_HENV; - else if (val.toUpper() == QLatin1String("SQL_CP_DEFAULT")) + else if (val.toUpper() == "SQL_CP_DEFAULT"_L1) v = SQL_CP_DEFAULT; else { qWarning() << "QODBCDriver::open: Unknown option value '" << val << '\''; continue; } r = SQLSetConnectAttr(hDbc, SQL_ATTR_CONNECTION_POOLING, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_CP_MATCH")) { - if (val.toUpper() == QLatin1String("SQL_CP_STRICT_MATCH")) + } else if (opt.toUpper() == "SQL_ATTR_CP_MATCH"_L1) { + if (val.toUpper() == "SQL_CP_STRICT_MATCH"_L1) v = SQL_CP_STRICT_MATCH; - else if (val.toUpper() == QLatin1String("SQL_CP_RELAXED_MATCH")) + else if (val.toUpper() == "SQL_CP_RELAXED_MATCH"_L1) v = SQL_CP_RELAXED_MATCH; - else if (val.toUpper() == QLatin1String("SQL_CP_MATCH_DEFAULT")) + else if (val.toUpper() == "SQL_CP_MATCH_DEFAULT"_L1) v = SQL_CP_MATCH_DEFAULT; else { qWarning() << "QODBCDriver::open: Unknown option value '" << val << '\''; continue; } r = SQLSetConnectAttr(hDbc, SQL_ATTR_CP_MATCH, (SQLPOINTER) size_t(v), 0); - } else if (opt.toUpper() == QLatin1String("SQL_ATTR_ODBC_VERSION")) { + } else if (opt.toUpper() == "SQL_ATTR_ODBC_VERSION"_L1) { // Already handled in QODBCDriver::open() continue; } else { @@ -974,7 +976,7 @@ QODBCResult::~QODBCResult() if (d->hStmt && d->isStmtHandleValid() && driver() && driver()->isOpen()) { SQLRETURN r = SQLFreeHandle(SQL_HANDLE_STMT, d->hStmt); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver: Unable to free statement handle ") + qSqlWarning("QODBCDriver: Unable to free statement handle "_L1 + QString::number(r), d); } } @@ -994,7 +996,7 @@ bool QODBCResult::reset (const QString& query) if (d->hStmt && d->isStmtHandleValid()) { r = SQLFreeHandle(SQL_HANDLE_STMT, d->hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCResult::reset: Unable to free statement handle"), d); + qSqlWarning("QODBCResult::reset: Unable to free statement handle"_L1, d); return false; } } @@ -1002,7 +1004,7 @@ bool QODBCResult::reset (const QString& query) d->dpDbc(), &d->hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCResult::reset: Unable to allocate statement handle"), d); + qSqlWarning("QODBCResult::reset: Unable to allocate statement handle"_L1, d); return false; } @@ -1330,7 +1332,7 @@ int QODBCResult::numRowsAffected() if (r == SQL_SUCCESS) return affectedRowCount; else - qSqlWarning(QLatin1String("QODBCResult::numRowsAffected: Unable to count affected rows"), d); + qSqlWarning("QODBCResult::numRowsAffected: Unable to count affected rows"_L1, d); return -1; } @@ -1345,7 +1347,7 @@ bool QODBCResult::prepare(const QString& query) if (d->hStmt && d->isStmtHandleValid()) { r = SQLFreeHandle(SQL_HANDLE_STMT, d->hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCResult::prepare: Unable to close statement"), d); + qSqlWarning("QODBCResult::prepare: Unable to close statement"_L1, d); return false; } } @@ -1353,7 +1355,7 @@ bool QODBCResult::prepare(const QString& query) d->dpDbc(), &d->hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCResult::prepare: Unable to allocate statement handle"), d); + qSqlWarning("QODBCResult::prepare: Unable to allocate statement handle"_L1, d); return false; } @@ -1399,7 +1401,7 @@ bool QODBCResult::exec() d->fieldCacheIdx = 0; if (!d->hStmt) { - qSqlWarning(QLatin1String("QODBCResult::exec: No statement handle available"), d); + qSqlWarning("QODBCResult::exec: No statement handle available"_L1, d); return false; } @@ -1797,13 +1799,13 @@ QVariant QODBCResult::lastInsertId() const switch (driver()->dbmsType()) { case QSqlDriver::MSSqlServer: case QSqlDriver::Sybase: - sql = QLatin1String("SELECT @@IDENTITY;"); + sql = "SELECT @@IDENTITY;"_L1; break; case QSqlDriver::MySqlServer: - sql = QLatin1String("SELECT LAST_INSERT_ID();"); + sql = "SELECT LAST_INSERT_ID();"_L1; break; case QSqlDriver::PostgreSQL: - sql = QLatin1String("SELECT lastval();"); + sql = "SELECT lastval();"_L1; break; default: break; @@ -1814,9 +1816,9 @@ QVariant QODBCResult::lastInsertId() const if (qry.exec(sql) && qry.next()) return qry.value(0); - qSqlWarning(QLatin1String("QODBCResult::lastInsertId: Unable to get lastInsertId"), d); + qSqlWarning("QODBCResult::lastInsertId: Unable to get lastInsertId"_L1, d); } else { - qSqlWarning(QLatin1String("QODBCResult::lastInsertId: not implemented for this DBMS"), d); + qSqlWarning("QODBCResult::lastInsertId: not implemented for this DBMS"_L1, d); } return QVariant(); @@ -1970,7 +1972,7 @@ bool QODBCDriver::open(const QString & db, SQL_NULL_HANDLE, &d->hEnv); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { - qSqlWarning(QLatin1String("QODBCDriver::open: Unable to allocate environment"), d); + qSqlWarning("QODBCDriver::open: Unable to allocate environment"_L1, d); setOpenError(true); return false; } @@ -1982,7 +1984,7 @@ bool QODBCDriver::open(const QString & db, d->hEnv, &d->hDbc); if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { - qSqlWarning(QLatin1String("QODBCDriver::open: Unable to allocate connection"), d); + qSqlWarning("QODBCDriver::open: Unable to allocate connection"_L1, d); setOpenError(true); cleanup(); return false; @@ -1996,18 +1998,18 @@ bool QODBCDriver::open(const QString & db, // Create the connection string QString connQStr; // support the "DRIVER={SQL SERVER};SERVER=blah" syntax - if (db.contains(QLatin1String(".dsn"), Qt::CaseInsensitive)) - connQStr = QLatin1String("FILEDSN=") + db; - else if (db.contains(QLatin1String("DRIVER="), Qt::CaseInsensitive) - || db.contains(QLatin1String("SERVER="), Qt::CaseInsensitive)) + if (db.contains(".dsn"_L1, Qt::CaseInsensitive)) + connQStr = "FILEDSN="_L1 + db; + else if (db.contains("DRIVER="_L1, Qt::CaseInsensitive) + || db.contains("SERVER="_L1, Qt::CaseInsensitive)) connQStr = db; else - connQStr = QLatin1String("DSN=") + db; + connQStr = "DSN="_L1 + db; if (!user.isEmpty()) - connQStr += QLatin1String(";UID=") + user; + connQStr += ";UID="_L1 + user; if (!password.isEmpty()) - connQStr += QLatin1String(";PWD=") + password; + connQStr += ";PWD="_L1 + password; SQLSMALLINT cb; QVarLengthArray<SQLTCHAR> connOut(1024); @@ -2046,7 +2048,7 @@ bool QODBCDriver::open(const QString & db, setOpenError(false); if (d->dbmsType == MSSqlServer) { QSqlQuery i(createResult()); - i.exec(QLatin1String("SET QUOTED_IDENTIFIER ON")); + i.exec("SET QUOTED_IDENTIFIER ON"_L1); } return true; } @@ -2068,21 +2070,21 @@ void QODBCDriver::cleanup() if (isOpen()) { r = SQLDisconnect(d->hDbc); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver::disconnect: Unable to disconnect datasource"), d); + qSqlWarning("QODBCDriver::disconnect: Unable to disconnect datasource"_L1, d); else d->disconnectCount++; } r = SQLFreeHandle(SQL_HANDLE_DBC, d->hDbc); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver::cleanup: Unable to free connection handle"), d); + qSqlWarning("QODBCDriver::cleanup: Unable to free connection handle"_L1, d); d->hDbc = 0; } if (d->hEnv) { r = SQLFreeHandle(SQL_HANDLE_ENV, d->hEnv); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver::cleanup: Unable to free environment handle"), d); + qSqlWarning("QODBCDriver::cleanup: Unable to free environment handle"_L1, d); d->hEnv = 0; } } @@ -2129,13 +2131,13 @@ void QODBCDriverPrivate::checkUnicode() hDbc, &hStmt); - r = SQLExecDirect(hStmt, toSQLTCHAR(QLatin1String("select 'test'")).data(), SQL_NTS); + r = SQLExecDirect(hStmt, toSQLTCHAR("select 'test'"_L1).data(), SQL_NTS); if (r == SQL_SUCCESS) { r = SQLFetch(hStmt); if (r == SQL_SUCCESS) { QVarLengthArray<SQLWCHAR> buffer(10); r = SQLGetData(hStmt, 1, SQL_C_WCHAR, buffer.data(), buffer.size() * sizeof(SQLWCHAR), NULL); - if (r == SQL_SUCCESS && fromSQLTCHAR(buffer) == QLatin1String("test")) { + if (r == SQL_SUCCESS && fromSQLTCHAR(buffer) == "test"_L1) { unicode = true; } } @@ -2167,7 +2169,7 @@ bool QODBCDriverPrivate::checkDriver() const r = SQLGetFunctions(hDbc, reqFunc[i], &sup); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::checkDriver: Cannot get list of supported functions"), this); + qSqlWarning("QODBCDriver::checkDriver: Cannot get list of supported functions"_L1, this); return false; } if (sup == SQL_FALSE) { @@ -2183,7 +2185,7 @@ bool QODBCDriverPrivate::checkDriver() const r = SQLGetFunctions(hDbc, optFunc[i], &sup); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::checkDriver: Cannot get list of supported functions"), this); + qSqlWarning("QODBCDriver::checkDriver: Cannot get list of supported functions"_L1, this); return false; } if (sup == SQL_FALSE) { @@ -2224,15 +2226,15 @@ void QODBCDriverPrivate::checkDBMS() &t); if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { const QString serverType = fromSQLTCHAR(serverString, t / sizeof(SQLTCHAR)); - if (serverType.contains(QLatin1String("PostgreSQL"), Qt::CaseInsensitive)) + if (serverType.contains("PostgreSQL"_L1, Qt::CaseInsensitive)) dbmsType = QSqlDriver::PostgreSQL; - else if (serverType.contains(QLatin1String("Oracle"), Qt::CaseInsensitive)) + else if (serverType.contains("Oracle"_L1, Qt::CaseInsensitive)) dbmsType = QSqlDriver::Oracle; - else if (serverType.contains(QLatin1String("MySql"), Qt::CaseInsensitive)) + else if (serverType.contains("MySql"_L1, Qt::CaseInsensitive)) dbmsType = QSqlDriver::MySqlServer; - else if (serverType.contains(QLatin1String("Microsoft SQL Server"), Qt::CaseInsensitive)) + else if (serverType.contains("Microsoft SQL Server"_L1, Qt::CaseInsensitive)) dbmsType = QSqlDriver::MSSqlServer; - else if (serverType.contains(QLatin1String("Sybase"), Qt::CaseInsensitive)) + else if (serverType.contains("Sybase"_L1, Qt::CaseInsensitive)) dbmsType = QSqlDriver::Sybase; } r = SQLGetInfo(hDbc, @@ -2242,7 +2244,7 @@ void QODBCDriverPrivate::checkDBMS() &t); if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) { const QString serverType = fromSQLTCHAR(serverString, t / sizeof(SQLTCHAR)); - isFreeTDSDriver = serverType.contains(QLatin1String("tdsodbc"), Qt::CaseInsensitive); + isFreeTDSDriver = serverType.contains("tdsodbc"_L1, Qt::CaseInsensitive); unicode = unicode && !isFreeTDSDriver; } } @@ -2381,7 +2383,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const d->hDbc, &hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::tables: Unable to allocate handle"), d); + qSqlWarning("QODBCDriver::tables: Unable to allocate handle"_L1, d); return tl; } r = SQLSetStmtAttr(hStmt, @@ -2390,11 +2392,11 @@ QStringList QODBCDriver::tables(QSql::TableType type) const SQL_IS_UINTEGER); QStringList tableType; if (type & QSql::Tables) - tableType += QLatin1String("TABLE"); + tableType += "TABLE"_L1; if (type & QSql::Views) - tableType += QLatin1String("VIEW"); + tableType += "VIEW"_L1; if (type & QSql::SystemTables) - tableType += QLatin1String("SYSTEM TABLE"); + tableType += "SYSTEM TABLE"_L1; if (tableType.isEmpty()) return tl; @@ -2411,7 +2413,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const joinedTableTypeString.length() /* characters, not bytes */); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver::tables Unable to execute table list"), d); + qSqlWarning("QODBCDriver::tables Unable to execute table list"_L1, d); if (d->hasSQLFetchScroll) r = SQLFetchScroll(hStmt, @@ -2439,7 +2441,7 @@ QStringList QODBCDriver::tables(QSql::TableType type) const r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r!= SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver: Unable to free statement handle") + QString::number(r), d); + qSqlWarning("QODBCDriver: Unable to free statement handle"_L1 + QString::number(r), d); return tl; } @@ -2457,7 +2459,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const d->hDbc, &hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::primaryIndex: Unable to list primary key"), d); + qSqlWarning("QODBCDriver::primaryIndex: Unable to list primary key"_L1, d); return index; } QString catalog, schema, table; @@ -2506,7 +2508,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const SQL_NULLABLE); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::primaryIndex: Unable to execute primary key list"), d); + qSqlWarning("QODBCDriver::primaryIndex: Unable to execute primary key list"_L1, d); } else { usingSpecialColumns = true; } @@ -2543,7 +2545,7 @@ QSqlIndex QODBCDriver::primaryIndex(const QString& tablename) const } r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r!= SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver: Unable to free statement handle") + QString::number(r), d); + qSqlWarning("QODBCDriver: Unable to free statement handle"_L1 + QString::number(r), d); return index; } @@ -2577,7 +2579,7 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const d->hDbc, &hStmt); if (r != SQL_SUCCESS) { - qSqlWarning(QLatin1String("QODBCDriver::record: Unable to allocate handle"), d); + qSqlWarning("QODBCDriver::record: Unable to allocate handle"_L1, d); return fil; } r = SQLSetStmtAttr(hStmt, @@ -2594,7 +2596,7 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const NULL, 0); if (r != SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver::record: Unable to execute column list"), d); + qSqlWarning("QODBCDriver::record: Unable to execute column list"_L1, d); if (d->hasSQLFetchScroll) r = SQLFetchScroll(hStmt, @@ -2618,7 +2620,7 @@ QSqlRecord QODBCDriver::record(const QString& tablename) const r = SQLFreeHandle(SQL_HANDLE_STMT, hStmt); if (r!= SQL_SUCCESS) - qSqlWarning(QLatin1String("QODBCDriver: Unable to free statement handle ") + QString::number(r), d); + qSqlWarning("QODBCDriver: Unable to free statement handle "_L1 + QString::number(r), d); return fil; } @@ -2628,23 +2630,23 @@ QString QODBCDriver::formatValue(const QSqlField &field, { QString r; if (field.isNull()) { - r = QLatin1String("NULL"); + r = "NULL"_L1; } else if (field.metaType().id() == QMetaType::QDateTime) { // Use an escape sequence for the datetime fields if (field.value().toDateTime().isValid()){ QDate dt = field.value().toDateTime().date(); QTime tm = field.value().toDateTime().time(); // Dateformat has to be "yyyy-MM-dd hh:mm:ss", with leading zeroes if month or day < 10 - r = QLatin1String("{ ts '") + + r = "{ ts '"_L1 + QString::number(dt.year()) + u'-' + QString::number(dt.month()).rightJustified(2, u'0', true) + u'-' + QString::number(dt.day()).rightJustified(2, u'0', true) + u' ' + tm.toString() + - QLatin1String("' }"); + "' }"_L1; } else - r = QLatin1String("NULL"); + r = "NULL"_L1; } else if (field.metaType().id() == QMetaType::QByteArray) { QByteArray ba = field.value().toByteArray(); QString res; @@ -2654,7 +2656,7 @@ QString QODBCDriver::formatValue(const QSqlField &field, res += QLatin1Char(hexchars[s >> 4]); res += QLatin1Char(hexchars[s & 0x0f]); } - r = QLatin1String("0x") + res; + r = "0x"_L1 + res; } else { r = QSqlDriver::formatValue(field, trimStrings); } diff --git a/src/plugins/sqldrivers/psql/main.cpp b/src/plugins/sqldrivers/psql/main.cpp index c31e6f64b7..07ee4ed4c7 100644 --- a/src/plugins/sqldrivers/psql/main.cpp +++ b/src/plugins/sqldrivers/psql/main.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QPSQLDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QPSQLDriverPlugin::QPSQLDriverPlugin() QSqlDriver* QPSQLDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QPSQL")) + if (name == "QPSQL"_L1) return new QPSQLDriver; return nullptr; } diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index ef4158c811..722a75ee56 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -193,7 +193,7 @@ void QPSQLDriverPrivate::appendTables(QStringList &tl, QSqlQuery &t, QChar type) t.exec(query); while (t.next()) { QString schema = t.value(1).toString(); - if (schema.isEmpty() || schema == QLatin1String("public")) + if (schema.isEmpty() || schema == "public"_L1) tl.append(t.value(0).toString()); else tl.append(t.value(0).toString().prepend(u'.').prepend(schema)); @@ -316,7 +316,7 @@ static QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, errorCode = QString::fromLatin1(PQresultErrorField(result, PG_DIAG_SQLSTATE)); msg += QString::fromLatin1("(%1)").arg(errorCode); } - return QSqlError(QLatin1String("QPSQL: ") + err, msg, type, errorCode); + return QSqlError("QPSQL: "_L1 + err, msg, type, errorCode); } bool QPSQLResultPrivate::processResults() @@ -863,7 +863,7 @@ static QString qCreateParamString(const QList<QVariant> &boundValues, const QSql else f.setValue(val); if (!params.isNull()) - params.append(QLatin1String(", ")); + params.append(", "_L1); params.append(driver->formatValue(f)); } return params; @@ -983,7 +983,7 @@ void QPSQLDriverPrivate::detectBackslashEscape() PGresult *result = exec(QStringLiteral("SELECT '\\\\' x")); int status = PQresultStatus(result); if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) - if (QString::fromLatin1(PQgetvalue(result, 0, 0)) == QLatin1String("\\")) + if (QString::fromLatin1(PQgetvalue(result, 0, 0)) == "\\"_L1) hasBackslashEscape = true; PQclear(result); } @@ -1095,9 +1095,9 @@ QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion() QPSQLDriver::Protocol clientVersion = #if defined(PG_MAJORVERSION) - qFindPSQLVersion(QLatin1String(PG_MAJORVERSION)); + qFindPSQLVersion(PG_MAJORVERSION ""_L1); #elif defined(PG_VERSION) - qFindPSQLVersion(QLatin1String(PG_VERSION)); + qFindPSQLVersion(PG_VERSION ""_L1); #else QPSQLDriver::VersionUnknown; #endif @@ -1185,8 +1185,8 @@ bool QPSQLDriver::hasFeature(DriverFeature f) const */ static QString qQuote(QString s) { - s.replace(u'\\', QLatin1String("\\\\")); - s.replace(u'\'', QLatin1String("\\'")); + s.replace(u'\\', "\\\\"_L1); + s.replace(u'\'', "\\'"_L1); s.append(u'\'').prepend(u'\''); return s; } @@ -1202,15 +1202,15 @@ bool QPSQLDriver::open(const QString &db, close(); QString connectString; if (!host.isEmpty()) - connectString.append(QLatin1String("host=")).append(qQuote(host)); + connectString.append("host="_L1).append(qQuote(host)); if (!db.isEmpty()) - connectString.append(QLatin1String(" dbname=")).append(qQuote(db)); + connectString.append(" dbname="_L1).append(qQuote(db)); if (!user.isEmpty()) - connectString.append(QLatin1String(" user=")).append(qQuote(user)); + connectString.append(" user="_L1).append(qQuote(user)); if (!password.isEmpty()) - connectString.append(QLatin1String(" password=")).append(qQuote(password)); + connectString.append(" password="_L1).append(qQuote(password)); if (port != -1) - connectString.append(QLatin1String(" port=")).append(qQuote(QString::number(port))); + connectString.append(" port="_L1).append(qQuote(QString::number(port))); // add any connect options - the server will handle error detection if (!connOpts.isEmpty()) { @@ -1504,7 +1504,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const case QMetaType::QString: r = QSqlDriver::formatValue(field, trimStrings); if (d->hasBackslashEscape) - r.replace(u'\\', QLatin1String("\\\\")); + r.replace(u'\\', "\\\\"_L1); break; case QMetaType::Bool: if (field.value().toBool()) @@ -1551,9 +1551,9 @@ QString QPSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType) { QString res = identifier; if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) { - res.replace(u'"', QLatin1String("\"\"")); + res.replace(u'"', "\"\""_L1); res.prepend(u'"').append(u'"'); - res.replace(u'.', QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index 122850bce0..baf39a891d 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -74,6 +74,8 @@ 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; @@ -82,10 +84,10 @@ static QString _q_escapeIdentifier(const QString &identifier, QSqlDriver::Identi if (identifier.contains(u'[') && identifier.contains(u']')) return res; if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"')) { - res.replace(u'"', QLatin1String("\"\"")); + res.replace(u'"', "\"\""_L1); res.prepend(u'"').append(u'"'); if (type == QSqlDriver::TableName) - res.replace(u'.', QLatin1String("\".\"")); + res.replace(u'.', "\".\""_L1); } return res; } @@ -94,18 +96,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; } @@ -728,7 +728,7 @@ 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 @@ -736,7 +736,7 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c 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(u'=')) { bool ok; @@ -744,13 +744,13 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c 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) @@ -841,7 +841,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 +856,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 +871,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 +889,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 +907,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; @@ -933,7 +933,7 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only } } } - q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info (") + + q.exec("PRAGMA "_L1 + schema + "table_info ("_L1 + _q_escapeIdentifier(table, QSqlDriver::TableName) + u')'); QSqlIndex ind; while (q.next()) { @@ -949,7 +949,7 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only } 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); diff --git a/src/plugins/sqldrivers/sqlite/smain.cpp b/src/plugins/sqldrivers/sqlite/smain.cpp index 092813990c..0427e6692e 100644 --- a/src/plugins/sqldrivers/sqlite/smain.cpp +++ b/src/plugins/sqldrivers/sqlite/smain.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QSQLiteDriverPlugin : public QSqlDriverPlugin { Q_OBJECT @@ -61,7 +63,7 @@ QSQLiteDriverPlugin::QSQLiteDriverPlugin() QSqlDriver* QSQLiteDriverPlugin::create(const QString &name) { - if (name == QLatin1String("QSQLITE")) { + if (name == "QSQLITE"_L1) { QSQLiteDriver* driver = new QSQLiteDriver(); return driver; } diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 1d69e8553f..e3ded2085c 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -55,9 +55,10 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QSqlDriverFactoryInterface_iid, - QLatin1String("/sqldrivers"))) + (QSqlDriverFactoryInterface_iid, "/sqldrivers"_L1)) const char *QSqlDatabase::defaultConnection = const_cast<char *>("qt_sql_default_connection"); diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp index 1c9979623f..eb8646d785 100644 --- a/src/sql/kernel/qsqldriver.cpp +++ b/src/sql/kernel/qsqldriver.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static QString prepareIdentifier(const QString &identifier, QSqlDriver::IdentifierType type, const QSqlDriver *driver) { @@ -487,12 +489,12 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, case SelectStatement: for (i = 0; i < rec.count(); ++i) { if (rec.isGenerated(i)) - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(", "_L1); } if (s.isEmpty()) return s; s.chop(2); - s = QLatin1String("SELECT ") + s + QLatin1String(" FROM ") + tableNameString; + s = "SELECT "_L1 + s + " FROM "_L1 + tableNameString; break; case WhereStatement: { @@ -501,20 +503,20 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, for (int i = 0; i < rec.count(); ++i) { if (!rec.isGenerated(i)) continue; - s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND ")); + s.append(s.isEmpty() ? "WHERE "_L1 : " AND "_L1); s.append(tableNamePrefix); s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); if (rec.isNull(i)) - s.append(QLatin1String(" IS NULL")); + s.append(" IS NULL"_L1); else if (preparedStatement) - s.append(QLatin1String(" = ?")); + s.append(" = ?"_L1); else - s.append(QLatin1String(" = ")).append(formatValue(rec.field(i))); + s.append(" = "_L1).append(formatValue(rec.field(i))); } break; } case UpdateStatement: - s = s + QLatin1String("UPDATE ") + tableNameString + QLatin1String(" SET "); + s = s + "UPDATE "_L1 + tableNameString + " SET "_L1; for (i = 0; i < rec.count(); ++i) { if (!rec.isGenerated(i)) continue; @@ -523,35 +525,35 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, s.append(u'?'); else s.append(formatValue(rec.field(i))); - s.append(QLatin1String(", ")); + s.append(", "_L1); } - if (s.endsWith(QLatin1String(", "))) + if (s.endsWith(", "_L1)) s.chop(2); else s.clear(); break; case DeleteStatement: - s = s + QLatin1String("DELETE FROM ") + tableNameString; + s = s + "DELETE FROM "_L1 + tableNameString; break; case InsertStatement: { - s = s + QLatin1String("INSERT INTO ") + tableNameString + QLatin1String(" ("); + s = s + "INSERT INTO "_L1 + tableNameString + " ("_L1; QString vals; for (i = 0; i < rec.count(); ++i) { if (!rec.isGenerated(i)) continue; - s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); + s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(", "_L1); if (preparedStatement) vals.append(u'?'); else vals.append(formatValue(rec.field(i))); - vals.append(QLatin1String(", ")); + vals.append(", "_L1); } if (vals.isEmpty()) { s.clear(); } else { vals.chop(2); // remove trailing comma s[s.length() - 2] = u')'; - s.append(QLatin1String("VALUES (")).append(vals).append(u')'); + s.append("VALUES ("_L1).append(vals).append(u')'); } break; } } @@ -593,7 +595,7 @@ QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, */ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const { - const QLatin1String nullTxt("NULL"); + const auto nullTxt = "NULL"_L1; QString r; if (field.isNull()) @@ -603,7 +605,7 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const case QMetaType::Int: case QMetaType::UInt: if (field.value().userType() == QMetaType::Bool) - r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); + r = field.value().toBool() ? "1"_L1 : "0"_L1; else r = field.value().toString(); break; @@ -638,7 +640,7 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const result.truncate(end); } /* escape the "'" character */ - result.replace(u'\'', QLatin1String("''")); + result.replace(u'\'', "''"_L1); r = u'\'' + result + u'\''; break; } diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp index 2fb0599287..22ed6f6a4c 100644 --- a/src/sql/kernel/qsqlerror.cpp +++ b/src/sql/kernel/qsqlerror.cpp @@ -42,6 +42,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QSqlError &s) { @@ -243,7 +245,7 @@ QString QSqlError::nativeErrorCode() const QString QSqlError::text() const { QString result = d->databaseError; - if (!d->databaseError.isEmpty() && !d->driverError.isEmpty() && !d->databaseError.endsWith(QLatin1String("\n"))) + if (!d->databaseError.isEmpty() && !d->driverError.isEmpty() && !d->databaseError.endsWith("\n"_L1)) result += u' '; result += d->driverError; return result; diff --git a/src/sql/kernel/qsqlindex.cpp b/src/sql/kernel/qsqlindex.cpp index 068a6892ac..71d4f6d2c9 100644 --- a/src/sql/kernel/qsqlindex.cpp +++ b/src/sql/kernel/qsqlindex.cpp @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QSqlIndex \brief The QSqlIndex class provides functions to manipulate and @@ -176,7 +178,7 @@ QString QSqlIndex::createField(int i, const QString& prefix, bool verbose) const f += prefix + u'.'; f += field(i).name(); if (verbose) - f += u' ' + QString((isDescending(i) ? QLatin1String("DESC") : QLatin1String("ASC"))); + f += u' ' + QString((isDescending(i) ? "DESC"_L1 : "ASC"_L1)); return f; } diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index 860622fb24..e3ac047026 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QString QSqlResultPrivate::holderAt(int index) const { return holders.size() > index ? holders.at(index).holderName : fieldSerial(index); @@ -62,7 +64,7 @@ QString QSqlResultPrivate::holderAt(int index) const QString QSqlResultPrivate::fieldSerial(int i) const { - return QString(QLatin1String(":%1")).arg(i); + return QString(":%1"_L1).arg(i); } static bool qIsAlnum(QChar ch) @@ -118,7 +120,7 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) // caller to make sure that it is not using named bindings for the wrong // parts of the query since Interbase uses them literally if (sqldriver->dbmsType() == QSqlDriver::Interbase && - query.trimmed().startsWith(QLatin1String("EXECUTE BLOCK"), Qt::CaseInsensitive)) + query.trimmed().startsWith("EXECUTE BLOCK"_L1, Qt::CaseInsensitive)) return query; int n = query.size(); @@ -667,7 +669,7 @@ bool QSqlResult::exec() for (i = d->holders.count() - 1; i >= 0; --i) { holder = d->holders.at(i).holderName; val = d->values.value(d->indexes.value(holder).value(0,-1)); - QSqlField f(QLatin1String(""), val.metaType()); + QSqlField f(""_L1, val.metaType()); if (QSqlResultPrivate::isVariantNull(val)) f.setValue(QVariant()); else @@ -684,7 +686,7 @@ bool QSqlResult::exec() if (i == -1) continue; QVariant var = d->values.value(idx); - QSqlField f(QLatin1String(""), var.metaType()); + QSqlField f(""_L1, var.metaType()); if (QSqlResultPrivate::isVariantNull(var)) f.clear(); else diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index 674b3f258b..2e37c9e5aa 100644 --- a/src/sql/models/qsqlquerymodel.cpp +++ b/src/sql/models/qsqlquerymodel.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #define QSQL_PREFETCH 255 void QSqlQueryModelPrivate::prefetch(int limit) @@ -463,8 +465,7 @@ void QSqlQueryModel::setQuery(QSqlQuery &&query) d->atEnd = true; if (d->query.isForwardOnly()) { - d->error = QSqlError(QLatin1String("Forward-only queries " - "cannot be used in a data model"), + d->error = QSqlError("Forward-only queries cannot be used in a data model"_L1, QString(), QSqlError::ConnectionError); endResetModel(); return; diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp index 8ac5d67371..ffabf83831 100644 --- a/src/sql/models/qsqlrelationaltablemodel.cpp +++ b/src/sql/models/qsqlrelationaltablemodel.cpp @@ -55,10 +55,12 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QSqlRelationalTableModelSql: public QSqlTableModelSql { public: - inline const static QString relTablePrefix(int i) { return QString::number(i).prepend(QLatin1String("relTblAl_")); } + inline const static QString relTablePrefix(int i) { return QString::number(i).prepend("relTblAl_"_L1); } }; typedef QSqlRelationalTableModelSql Sql; diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index c793b946dd..4e534bd15b 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + typedef QSqlTableModelSql Sql; QSqlTableModelPrivate::~QSqlTableModelPrivate() @@ -333,7 +335,7 @@ void QSqlTableModel::setTable(const QString &tableName) d->initRecordAndPrimaryIndex(); if (d->rec.count() == 0) - d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), + d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(), QSqlError::StatementError); // Remember the auto index column if there is one now. @@ -493,9 +495,9 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in if (orientation == Qt::Vertical && role == Qt::DisplayRole) { const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); if (op == QSqlTableModelPrivate::Insert) - return QLatin1String("*"); + return "*"_L1; else if (op == QSqlTableModelPrivate::Delete) - return QLatin1String("!"); + return "!"_L1; } return QSqlQueryModel::headerData(section, orientation, role); } @@ -657,8 +659,7 @@ bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) whereValues, prepStatement); if (stmt.isEmpty() || where.isEmpty() || row < 0 || row >= rowCount()) { - d->error = QSqlError(QLatin1String("No Fields to update"), QString(), - QSqlError::StatementError); + d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError); return false; } @@ -690,8 +691,7 @@ bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values) rec, prepStatement); if (stmt.isEmpty()) { - d->error = QSqlError(QLatin1String("No Fields to update"), QString(), - QSqlError::StatementError); + d->error = QSqlError("No Fields to update"_L1, QString(), QSqlError::StatementError); return false; } @@ -727,8 +727,7 @@ bool QSqlTableModel::deleteRowFromTable(int row) prepStatement); if (stmt.isEmpty() || where.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), - QSqlError::StatementError); + d->error = QSqlError("Unable to delete row"_L1, QString(), QSqlError::StatementError); return false; } @@ -1029,12 +1028,11 @@ QString QSqlTableModel::selectStatement() const { Q_D(const QSqlTableModel); if (d->tableName.isEmpty()) { - d->error = QSqlError(QLatin1String("No table name given"), QString(), - QSqlError::StatementError); + d->error = QSqlError("No table name given"_L1, QString(), QSqlError::StatementError); return QString(); } if (d->rec.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), + d->error = QSqlError("Unable to find table "_L1 + d->tableName, QString(), QSqlError::StatementError); return QString(); } @@ -1044,7 +1042,7 @@ QString QSqlTableModel::selectStatement() const d->rec, false); if (stmt.isEmpty()) { - d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, + d->error = QSqlError("Unable to select fields from table "_L1 + d->tableName, QString(), QSqlError::StatementError); return stmt; } |