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 <andy.shaw@qt.io>bb10
parent
993f318014
commit
f2dba19194
|
|
@ -325,6 +325,14 @@ bool QSqlQuery::isNull(int field) const
|
|||
|| d->sqlResult->isNull(field);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
bool QSqlQuery::isNull(const QString &name) const
|
||||
{
|
||||
return isNull(QStringView(name));
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
|
@ -333,13 +341,12 @@ bool QSqlQuery::isNull(int field) const
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -436,6 +443,14 @@ QVariant QSqlQuery::value(int index) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
QVariant QSqlQuery::value(const QString &name) const
|
||||
{
|
||||
return value(QStringView(name));
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
|
@ -444,13 +459,12 @@ QVariant QSqlQuery::value(int index) const
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue