summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sql/kernel/qsqlquery.cpp17
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp3
2 files changed, 12 insertions, 8 deletions
diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp
index 661a582afe..e5f4c5fc56 100644
--- a/src/sql/kernel/qsqlquery.cpp
+++ b/src/sql/kernel/qsqlquery.cpp
@@ -309,19 +309,20 @@ QSqlQuery& QSqlQuery::operator=(const QSqlQuery& other)
}
/*!
- Returns \c true if the query is \l{isActive()}{active} and positioned
- on a valid record and the \a field is NULL; otherwise returns
- false. Note that for some drivers, isNull() will not return accurate
- information until after an attempt is made to retrieve data.
+ Returns \c true if the query is not \l{isActive()}{active},
+ the query is not positioned on a valid record,
+ there is no such field, or the field is null; otherwise \c false.
+ Note that for some drivers, isNull() will not return accurate
+ information until after an attempt is made to retrieve data.
- \sa isActive(), isValid(), value()
+ \sa isActive(), isValid(), value()
*/
bool QSqlQuery::isNull(int field) const
{
- if (d->sqlResult->isActive() && d->sqlResult->isValid())
- return d->sqlResult->isNull(field);
- return true;
+ return !d->sqlResult->isActive()
+ || !d->sqlResult->isValid()
+ || d->sqlResult->isNull(field);
}
/*!
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 1a100ce706..9098d5b101 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -1393,6 +1393,9 @@ void tst_QSqlQuery::isNull()
QVERIFY( q.next() );
QVERIFY( !q.isNull( 0 ) );
QVERIFY( !q.isNull( 1 ) );
+
+ // For a non existent field, it should be returning true.
+ QVERIFY(q.isNull(2));
}
/*! TDS specific BIT field test */