[Qt-interest] SQL (ODBC) retreiving doubles incorrectly
Bill King
bill.king at nokia.com
Mon Oct 5 01:59:46 CEST 2009
On 10/02/2009 10:27 PM, ext Andre Somers wrote:
> Julien Cugnière wrote:
>
>> 2009/10/2 Andre Somers <andre at familiesomers.nl>
>>
>>
>>> use qDebug() << on the variant value returned from the query, I get
>>> QVariant(QString, "E-3") as the result. Retreiving the type of the field
>>> using QSqlRecord::field() and QSqlField::type() returns QVariant::double
>>> though.
>>>
>>>
>> You can try using query.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble).
>>
>> If you don't, Qt often returns number as strings in order to preserve
>> the precision of the database, which can be greater than that of a
>> double. AFAIK, the exact format of the string is database-dependant,
>> and there's no guarantee it can be parsed by QString::toDouble.
>>
>>
>>
>>
> Thanks for the tip, I had not looked into this option before.
> Unfortunately, it makes things worse. Instead of an QVariant(QString,
> "E-3") on my debug, I now get an QVariant(, ). That probably means an
> empty or invalid value. Not a real improvement over the string...
>
> I have hacked around the issue for now by multiplying the value I am
> after in my query, and deviding it by the same value again after
> retreiving it. Still, this is an extremely ugly hack, and I'd like to
> get rid of it...
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
Can I get you to check the lastError() when it returns a null variant?
Looks like it's possibly getting an error.
Looks suspiciously like an Access via odbc bug. I'll try and get a
system up sometime this week and see if I can't take a squiz at it.
--
Bill King, Software Engineer
Qt Development Frameworks, Nokia Pty Ltd
Brisbane Office
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091005/ca700e37/attachment.html
More information about the Qt-interest-old
mailing list