[Qt-interest] QSqlQuery::isNull() behavior on MySQL
Jiri Horky
jiri.horky at gmail.com
Sun Feb 27 12:41:43 CET 2011
Hello,
I am experiencing strange problem with QSqlQuery and isNull() function
using MYSQL backend.
I have an application that returns some data from db formated in XML
upon user's request. Right now, I have only one record in database, so I
always return the same data. The query's result consists of many
columns, some of which can be NULL. Prior to returning the data to
client, I want to filter out these NULL values.
Getting the data from one column looks like this (query is a local
variable of the function):
index = query.record().indexOf("country");
if ( ! query.isNull(index)) {
t->setCountry(query.value(index).toString());
}
When a first client connects, the isNull() function correctly returns
true on columns where the NULL value really is. However, when a second
clients make the request, it returns false on such columns and thus
query.value(index).toString() triggers a Warning:
WARNING: QSqlQuery::value: not positioned on a valid record
Please note that it returns correct values on columns with non-NULL values.
If it matter, I am in multiple threads environment, but I am pretty sure
I access the database only from one thread that made the connection to it.
The execution of my application is not affected, but I would like to get
rid of these warnings.
According to documentation, the isNull() function can behave incorrectly
on some DB engines, but sadly, it doesn't say on which ones. If this is
the case for MYSQL, what is the correct way to solve my problem?
Thank you in advance
Jiri Horky
More information about the Qt-interest-old
mailing list