How to correctly read DECIMAL values from MySQL with QSqlQuery
Having a table in MySQL with a column of type DECIMAL, I am wondering how to read this value properly in my Qt application. To me it seems like it is handled like a double when you retrieve it using QSqlQuery. Is this correct? Doesn't this risk losing precision?
Now that the database is storing the monetary values accurately, you don’t want to do anything to lose that accuracy when retrieving values from it. [...] when using Java’s Hibernate ORM, you need to specify the variable as a BigDecimal not a Float or Double
Indeed, DECIMAL is mapped to double in the MySQL plugin.
You should do some testing with the values you are going to use.
What does this mean exactly? That the SQL classes of Qt cannot be used if you want the precision of DECIMAL?
As it is now, double is used.
Depending on how your DECIMAL filed is configured, it might be enough. If not, then you can modify the plugin to read the field as described here.