QSqlQuery::isNull string overload
Introduce isNull overload to take field name as a parameter.
This is corresponding to the commit
7e6e141234
Change-Id: I122f79707d26eaa09c2f38dc31aeee1dac7de33b
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
This commit is contained in:
parent
ded6a7081b
commit
c3c424b384
@ -325,6 +325,24 @@ bool QSqlQuery::isNull(int field) const
|
||||
|| d->sqlResult->isNull(field);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
Returns 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
|
||||
{
|
||||
int index = d->sqlResult->record().indexOf(name);
|
||||
if (index > -1)
|
||||
return isNull(index);
|
||||
qWarning("QSqlQuery::isNull: unknown field name '%s'", qPrintable(name));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Executes the SQL in \a query. Returns \c true and sets the query state
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
bool isValid() const;
|
||||
bool isActive() const;
|
||||
bool isNull(int field) const;
|
||||
bool isNull(const QString &name) const;
|
||||
int at() const;
|
||||
QString lastQuery() const;
|
||||
int numRowsAffected() const;
|
||||
|
@ -1384,7 +1384,9 @@ void tst_QSqlQuery::isNull()
|
||||
QVERIFY_SQL(q, exec("select id, t_varchar from " + qTableName("qtest_null", __FILE__, db) + " order by id"));
|
||||
QVERIFY( q.next() );
|
||||
QVERIFY( !q.isNull( 0 ) );
|
||||
QVERIFY(!q.isNull("id"));
|
||||
QVERIFY( q.isNull( 1 ) );
|
||||
QVERIFY(q.isNull("t_varchar"));
|
||||
QCOMPARE( q.value( 0 ).toInt(), 0 );
|
||||
QCOMPARE( q.value( 1 ).toString(), QString() );
|
||||
QVERIFY( !q.value( 0 ).isNull() );
|
||||
@ -1392,10 +1394,13 @@ void tst_QSqlQuery::isNull()
|
||||
|
||||
QVERIFY( q.next() );
|
||||
QVERIFY( !q.isNull( 0 ) );
|
||||
QVERIFY(!q.isNull("id"));
|
||||
QVERIFY( !q.isNull( 1 ) );
|
||||
QVERIFY(!q.isNull("t_varchar"));
|
||||
|
||||
// For a non existent field, it should be returning true.
|
||||
QVERIFY(q.isNull(2));
|
||||
QVERIFY(q.isNull("unknown"));
|
||||
}
|
||||
|
||||
/*! TDS specific BIT field test */
|
||||
|
Loading…
Reference in New Issue
Block a user