View Full Version : QtSql data type mappings

12th November 2009, 19:18
In debugging my DB-driven application, I happened on this documentation page talking about how DB data types are mapped into QVariant flavors.


Notably, I was surprised to find (for ODBC, which I am using, but also for other drivers) that 32/64bit float/double DB types are mapped "by default" to QString's! So my questions are thus:

What is the reasoning behind this? I would think to avoid precision loss--but IEEE 754 double's are guaranteed to be 64bit. So why not use double's instead of QString?
The docs explicitly says "by default" w/r/t to this mapping. Does that imply I can alter this mapping, and if so, how? Unfortunately, I don't see anything obvious in any of the likely QtSql classes (QSqlDatabase; QSqlDriver).

I was surprised cursory google didn't reveal answers to either query. Appreciate any insights.

Tanuki-no Torigava
23rd November 2009, 12:40
Having the same problem. Is I notice that behavior easy to change with the patch in Qt ODBC driver. So I did :)

P.S. This is my own patch and I think it will never go upstream though.

16th December 2009, 18:22
This issue popped up again debugging some code and I just noticed the reply as well.

The only update I have is an increased suspicion that the reasoning *may* be a loss-of-precision thing. Despite the IEEE 754 usage, a while back I was having funny behavior with high-precision numbers losing a digit when I did the QString>double conversion. IIRC, this only happened when 1) there were many (16 or 17 I'm guessing?) digits and 2) all digits were in the fractional part (e.g., 0.12435678901234567).

I didn't investigate this very thoroughly because other factors made the issue moot, but perhaps this will help someone (or stoke someone to look into it... maybe I will sometime later).