diff options
author | Christian Ehrlicher <[email protected]> | 2023-12-22 20:57:35 +0100 |
---|---|---|
committer | Christian Ehrlicher <[email protected]> | 2024-01-10 04:11:52 +0100 |
commit | f2dba1919427bcc0f510d7f60e3fafbd6f41430d (patch) | |
tree | 6a179305d44aacfaecb0ae006f61ca06114b5f0f | |
parent | 993f31801446c1d851c7c8d54c9b55216acd0993 (diff) |
QSqlQuery: Add QStringView overloads
Add an overload to QSqlQuery::isNull()/::value() taking a QStringView -
those two functions can now use the newly introduced
QSqlRecord::indexOf(QStringView)
[ChangeLog][QtSql][QSqlRecord] QSqlQuery::isNull() and value() gained a
new overload taking a QStringView.
Change-Id: Icebce88b94a7413130bdd7ec0098f51726d05892
Reviewed-by: Andy Shaw <[email protected]>
-rw-r--r-- | src/sql/kernel/qsqlquery.cpp | 26 | ||||
-rw-r--r-- | src/sql/kernel/qsqlquery.h | 4 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index d2147fc9957..94356dc3c93 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -327,19 +327,26 @@ bool QSqlQuery::isNull(int field) const /*! \overload +*/ +bool QSqlQuery::isNull(const QString &name) const +{ + return isNull(QStringView(name)); +} + +/*! + \overload Returns \c true if there is no field with this \a name; otherwise returns isNull(int index) for the corresponding field index. This overload is less efficient than \l{QSqlQuery::}{isNull()} */ - -bool QSqlQuery::isNull(const QString &name) const +bool QSqlQuery::isNull(QStringView name) const { qsizetype index = d->sqlResult->record().indexOf(name); if (index > -1) return isNull(index); - qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name)); + qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name.toString())); return true; } @@ -438,19 +445,26 @@ QVariant QSqlQuery::value(int index) const /*! \overload +*/ +QVariant QSqlQuery::value(const QString &name) const +{ + return value(QStringView(name)); +} + +/*! + \overload Returns the value of the field called \a name in the current record. If field \a name does not exist an invalid variant is returned. This overload is less efficient than \l{QSqlQuery::}{value()} */ - -QVariant QSqlQuery::value(const QString& name) const +QVariant QSqlQuery::value(QStringView name) const { qsizetype index = d->sqlResult->record().indexOf(name); if (index > -1) return value(index); - qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name)); + qWarning("QSqlQuery::value: unknown field name '%s'", qPrintable(name.toString())); return QVariant(); } diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h index e0071575d88..c5c62453055 100644 --- a/src/sql/kernel/qsqlquery.h +++ b/src/sql/kernel/qsqlquery.h @@ -50,6 +50,7 @@ public: bool isActive() const; bool isNull(int field) const; bool isNull(const QString &name) const; + bool isNull(QStringView name) const; int at() const; QString lastQuery() const; int numRowsAffected() const; @@ -64,7 +65,8 @@ public: void setForwardOnly(bool forward); bool exec(const QString& query); QVariant value(int i) const; - QVariant value(const QString& name) const; + QVariant value(const QString &name) const; + QVariant value(QStringView name) const; void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; |