[Qt-interest] QSqlQuery::isNull() behavior on MySQL

Jiri Horky jiri.horky at gmail.com
Sun Feb 27 14:17:12 CET 2011


Hello,

digging into it a bit with valgrind I discovered that the

"query.isNull(index)" call [ see example from the previous post]  
depends on uninitialized value allocated at mysql code:

==25356==  Uninitialised value was created by a heap allocation
==25356==    at 0x4025C4C: malloc (vg_replace_malloc.c:195)
==25356==    by 0x6110B5D: my_malloc (my_malloc.c:35)
==25356==    by 0x6114084: alloc_root (my_alloc.c:217)
==25356==    by 0x6137EE7: cli_read_rows (client.c:1414)
==25356==    by 0x6135F2F: mysql_store_result (client.c:2954)
==25356==    by 0x4040762: QMYSQLResult::reset(QString const&) 
(qsql_mysql.cpp:701)
==25356==    by 0x4083FE0: QSqlQuery::exec(QString const&) 
(qsqlquery.cpp:374)
....
....

It seems to me as a bug either in mysql or in Qt [it it's mysql's 
expected behavior on NULL values].

I am using Qt 4.6.3 and mysql-5.1.51 on a Gentoo host.

Best regards
Jiri Horky

On 02/27/2011 12:41 PM, Jiri Horky wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list