diff options
Diffstat (limited to 'src/sql/drivers')
-rw-r--r-- | src/sql/drivers/db2/qsql_db2.cpp | 2 | ||||
-rw-r--r-- | src/sql/drivers/ibase/qsql_ibase.cpp | 6 | ||||
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 11 | ||||
-rw-r--r-- | src/sql/drivers/oci/qsql_oci.cpp | 16 | ||||
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 21 | ||||
-rw-r--r-- | src/sql/drivers/psql/qsql_psql.cpp | 22 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 4 | ||||
-rw-r--r-- | src/sql/drivers/sqlite2/qsql_sqlite2.cpp | 6 | ||||
-rw-r--r-- | src/sql/drivers/tds/qsql_tds.cpp | 6 |
9 files changed, 44 insertions, 50 deletions
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp index 11d0041..c7cbc9b 100644 --- a/src/sql/drivers/db2/qsql_db2.cpp +++ b/src/sql/drivers/db2/qsql_db2.cpp @@ -1666,7 +1666,7 @@ QVariant QDB2Driver::handle() const QString QDB2Driver::escapeIdentifier(const QString &identifier, IdentifierType) const { QString res = identifier; - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 1645555..199ad8e 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -1732,7 +1732,7 @@ bool QIBaseDriver::subscribeToNotificationImplementation(const QString &name) eBuffer->resultBuffer); if (status[0] == 1 && status[1]) { - setLastError(QSqlError(QString(QLatin1String("Could not subscribe to event notifications for %1.")).arg(name))); + setLastError(QSqlError(QString::fromLatin1("Could not subscribe to event notifications for %1.").arg(name))); d->eventBuffers.remove(name); qFreeEventBuffer(eBuffer); return false; @@ -1760,7 +1760,7 @@ bool QIBaseDriver::unsubscribeFromNotificationImplementation(const QString &name isc_cancel_events(status, &d->ibase, &eBuffer->eventId); if (status[0] == 1 && status[1]) { - setLastError(QSqlError(QString(QLatin1String("Could not unsubscribe from event notifications for %1.")).arg(name))); + setLastError(QSqlError(QString::fromLatin1("Could not unsubscribe from event notifications for %1.").arg(name))); return false; } @@ -1818,7 +1818,7 @@ void QIBaseDriver::qHandleEventNotification(void *updatedResultBuffer) QString QIBaseDriver::escapeIdentifier(const QString &identifier, IdentifierType) const { QString res = identifier; - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 53645c9..82ed124 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -1468,7 +1468,7 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons QString QMYSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType) const { QString res = identifier; - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('`')) && identifier.right(1) != QString(QLatin1Char('`')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('`')) && !identifier.endsWith(QLatin1Char('`')) ) { res.prepend(QLatin1Char('`')).append(QLatin1Char('`')); res.replace(QLatin1Char('.'), QLatin1String("`.`")); } @@ -1478,12 +1478,9 @@ QString QMYSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType bool QMYSQLDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const { Q_UNUSED(type); - bool isLeftDelimited = (identifier.left(1) == QString(QLatin1Char('`'))); - bool isRightDelimited = (identifier.right(1) == QString(QLatin1Char('`'))); - if( identifier.size() > 2 && isLeftDelimited && isRightDelimited ) - return true; - else - return false; + return identifier.size() > 2 + && identifier.startsWith(QLatin1Char('`')) //left delimited + && identifier.endsWith(QLatin1Char('`')); //right delimited } QT_END_NAMESPACE diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp index a7031b1..e6ee63d 100644 --- a/src/sql/drivers/oci/qsql_oci.cpp +++ b/src/sql/drivers/oci/qsql_oci.cpp @@ -2040,8 +2040,8 @@ bool QOCIDriver::open(const QString & db, QString connectionString = db; if (!hostname.isEmpty()) connectionString = - QString(QLatin1String("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))" - "(CONNECT_DATA=(SID=%3)))")).arg(hostname).arg((port > -1 ? port : 1521)).arg(db); + QString::fromLatin1("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))" + "(CONNECT_DATA=(SID=%3)))").arg(hostname).arg((port > -1 ? port : 1521)).arg(db); r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->srvhp), OCI_HTYPE_SERVER, 0, 0); if (r == OCI_SUCCESS) @@ -2219,7 +2219,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const while (t.next()) { if (t.value(0).toString().toUpper() != user.toUpper()) - tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString()); + tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); else tl.append(t.value(1).toString()); } @@ -2235,7 +2235,7 @@ QStringList QOCIDriver::tables(QSql::TableType type) const "and owner != 'WMSYS'")); while (t.next()) { if (t.value(0).toString().toUpper() != d->user.toUpper()) - tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString()); + tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString()); else tl.append(t.value(1).toString()); } @@ -2297,7 +2297,7 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const else owner = owner.toUpper(); - tmpStmt += QLatin1String(" and owner='") + owner + QLatin1String("'"); + tmpStmt += QLatin1String(" and owner='") + owner + QLatin1Char('\''); t.setForwardOnly(true); t.exec(tmpStmt); if (!t.next()) { // try and see if the tablename is a synonym @@ -2352,7 +2352,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const else table = table.toUpper(); - tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1String("'"); + tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1Char('\''); if (owner.isEmpty()) { owner = d->user; } @@ -2362,7 +2362,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const else owner = owner.toUpper(); - tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1String("'"); + tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\''); t.setForwardOnly(true); t.exec(tmpStmt); @@ -2386,7 +2386,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const 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='") + - owner +QLatin1String("'")); + owner + QLatin1Char('\'')); if (!tt.next()) { return QSqlIndex(); } diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index ee500a0..8eaa8bf 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -213,14 +213,14 @@ static QString qWarnODBCHandle(int handleType, SQLHANDLE handle, int *nativeCode static QString qODBCWarn(const QODBCPrivate* odbc, int *nativeCode = 0) { - return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1String(" ") - + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc) + QLatin1String(" ") + return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ') + + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc) + QLatin1Char(' ') + qWarnODBCHandle(SQL_HANDLE_STMT, odbc->hStmt, nativeCode)); } static QString qODBCWarn(const QODBCDriverPrivate* odbc, int *nativeCode = 0) { - return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1String(" ") + return (qWarnODBCHandle(SQL_HANDLE_ENV, odbc->hEnv) + QLatin1Char(' ') + qWarnODBCHandle(SQL_HANDLE_DBC, odbc->hDbc, nativeCode)); } @@ -2414,12 +2414,12 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) { QString res = identifier; if (d->isMySqlServer) { - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('`')) && identifier.right(1) != QString(QLatin1Char('`')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('`')) && !identifier.endsWith(QLatin1Char('`')) ) { res.prepend(QLatin1Char('`')).append(QLatin1Char('`')); res.replace(QLatin1Char('.'), QLatin1String("`.`")); } } else { - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); @@ -2430,13 +2430,10 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType) bool QODBCDriver::isIdentifierEscapedImplementation(const QString &identifier, IdentifierType) const { - QString quote = d->quoteChar(); - bool isLeftDelimited = identifier.left(1) == quote; - bool isRightDelimited = identifier.right(1) == quote; - if( identifier.size() > 2 && isLeftDelimited && isRightDelimited ) - return true; - else - return false; + QChar quote = d->quoteChar(); + return identifier.size() > 2 + && identifier.startsWith(quote) //left delimited + && identifier.endsWith(quote); //right delimited } QT_END_NAMESPACE diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 16d19f1..ce0b8c5 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -541,7 +541,7 @@ bool QPSQLResult::prepare(const QString &query) qDeallocatePreparedStmt(d); const QString stmtId = qMakePreparedStmtId(); - const QString stmt = QString(QLatin1String("PREPARE %1 AS ")).arg(stmtId).append(qReplacePlaceholderMarkers(query)); + const QString stmt = QString::fromLatin1("PREPARE %1 AS ").arg(stmtId).append(qReplacePlaceholderMarkers(query)); PGresult *result = PQexec(d->driver->connection, d->driver->isUtf8 ? stmt.toUtf8().constData() @@ -570,9 +570,9 @@ bool QPSQLResult::exec() QString stmt; const QString params = qCreateParamString(boundValues(), d->q->driver()); if (params.isEmpty()) - stmt = QString(QLatin1String("EXECUTE %1")).arg(d->preparedStmtId); + stmt = QString::fromLatin1("EXECUTE %1").arg(d->preparedStmtId); else - stmt = QString(QLatin1String("EXECUTE %1 (%2)")).arg(d->preparedStmtId).arg(params); + stmt = QString::fromLatin1("EXECUTE %1 (%2)").arg(d->preparedStmtId).arg(params); d->result = PQexec(d->driver->connection, d->driver->isUtf8 ? stmt.toUtf8().constData() @@ -1102,12 +1102,12 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const QTime tm = field.value().toDateTime().time(); // msecs need to be right aligned otherwise psql // interpretes them wrong - r = QLatin1String("'") + QString::number(dt.year()) + QLatin1String("-") - + QString::number(dt.month()) + QLatin1String("-") - + QString::number(dt.day()) + QLatin1String(" ") - + tm.toString() + QLatin1String(".") + r = QLatin1Char('\'') + QString::number(dt.year()) + QLatin1Char('-') + + QString::number(dt.month()) + QLatin1Char('-') + + QString::number(dt.day()) + QLatin1Char(' ') + + tm.toString() + QLatin1Char('.') + QString::number(tm.msec()).rightJustified(3, QLatin1Char('0')) - + QLatin1String("'"); + + QLatin1Char('\''); } else { r = QLatin1String("NULL"); } @@ -1162,7 +1162,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const QString QPSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType) const { QString res = identifier; - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); @@ -1195,7 +1195,7 @@ bool QPSQLDriver::subscribeToNotificationImplementation(const QString &name) int socket = PQsocket(d->connection); if (socket) { - QString query = QString(QLatin1String("LISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName)); + QString query = QLatin1String("LISTEN ") + escapeIdentifier(name, QSqlDriver::TableName); if (PQresultStatus(PQexec(d->connection, d->isUtf8 ? query.toUtf8().constData() : query.toLocal8Bit().constData()) @@ -1227,7 +1227,7 @@ bool QPSQLDriver::unsubscribeFromNotificationImplementation(const QString &name) return false; } - QString query = QString(QLatin1String("UNLISTEN %1")).arg(escapeIdentifier(name, QSqlDriver::TableName)); + QString query = QLatin1String("UNLISTEN ") + escapeIdentifier(name, QSqlDriver::TableName); if (PQresultStatus(PQexec(d->connection, d->isUtf8 ? query.toUtf8().constData() : query.toLocal8Bit().constData()) diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index f732077..05d63ca 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -631,9 +631,9 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only { QString schema; QString table(tableName); - int indexOfSeparator = tableName.indexOf(QLatin1String(".")); + int indexOfSeparator = tableName.indexOf(QLatin1Char('.')); if (indexOfSeparator > -1) { - schema = tableName.left(indexOfSeparator).append(QLatin1String(".")); + schema = tableName.left(indexOfSeparator).append(QLatin1Char('.')); table = tableName.mid(indexOfSeparator + 1); } q.exec(QLatin1String("PRAGMA ") + schema + QLatin1String("table_info ('") + table + QLatin1String("')")); diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp index d0c6e18..cb72ff0 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp @@ -170,8 +170,8 @@ void QSQLite2ResultPrivate::init(const char **cnames, int numCols) //remove quotations around the field name if any QString fieldStr = QString::fromAscii(fieldName); - QString quote = QString::fromLatin1("\""); - if ( fieldStr.length() > 2 && fieldStr.left(1) == quote && fieldStr.right(1) == quote) { + QLatin1Char quote('\"'); + if ( fieldStr.length() > 2 && fieldStr.startsWith(quote) && fieldStr.endsWith(quote)) { fieldStr = fieldStr.mid(1); fieldStr.chop(1); } @@ -561,7 +561,7 @@ QVariant QSQLite2Driver::handle() const QString QSQLite2Driver::escapeIdentifier(const QString &identifier, IdentifierType /*type*/) const { QString res = identifier; - if(!identifier.isEmpty() && identifier.left(1) != QString(QLatin1Char('"')) && identifier.right(1) != QString(QLatin1Char('"')) ) { + if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) { res.replace(QLatin1Char('"'), QLatin1String("\"\"")); res.prepend(QLatin1Char('"')).append(QLatin1Char('"')); res.replace(QLatin1Char('.'), QLatin1String("\".\"")); diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp index 515f0de..298b008 100644 --- a/src/sql/drivers/tds/qsql_tds.cpp +++ b/src/sql/drivers/tds/qsql_tds.cpp @@ -181,7 +181,7 @@ static int CS_PUBLIC qTdsMsgHandler (DBPROCESS* dbproc, } if (severity > 0) { - QString errMsg = QString(QLatin1String("%1 (%2)")).arg(QString::fromAscii(msgtext)).arg( + QString errMsg = QString::fromLatin1("%1 (%2)").arg(QString::fromAscii(msgtext)).arg( msgstate); p->addErrorMsg(errMsg); } @@ -211,8 +211,8 @@ static int CS_PUBLIC qTdsErrHandler(DBPROCESS* dbproc, } - QString errMsg = QString(QLatin1String("%1 %2\n")).arg(QString::fromAscii(dberrstr)).arg( - QString::fromAscii(oserrstr)); + QString errMsg = QString::fromLatin1("%1 %2\n").arg(QLatin1String(dberrstr)).arg( + QLatin1String(oserrstr)); errMsg += p->getErrorMsgs(); p->lastError = qMakeError(errMsg, QSqlError::UnknownError, dberr); p->clearErrorMsgs(); |