You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@empire-db.apache.org by ivan nemeth <iv...@forumdigital.net> on 2014/07/29 17:27:12 UTC

BigDecimal scale question

Hi,

I try to define a DECIMAL column with precision 38 and scale 10.
The

WEIGHT = addColumn("weight", DataType.DECIMAL, 38.10, true);

doesn't work, but the following is ok:

WEIGHT = addColumn("weight", DataType.DECIMAL, 38.99, true);

and it generates a column with type decimal(38, 10)  (MySql).
In queries it works fine, the extracted BigDecimal value has the expected
scale of 10. The problem is when I want to update/insert a row, where the
BigDecimal value has a scale of 10, the following exception is thrown:

 org.apache.empire.db.exceptions.FieldValueOutOfRangeException: The value
supplied for field ![testdb.asset_composition.weight] is out of range.
at org.apache.empire.db.DBTableColumn.validateNumber(DBTableColumn.java:462)
 at org.apache.empire.db.DBTableColumn.validate(DBTableColumn.java:367)
at org.apache.empire.db.DBRecord.validateValue(DBRecord.java:619)
 at org.apache.empire.db.DBRecord.setValue(DBRecord.java:572)
at org.apache.empire.db.DBRecord.setValue(DBRecord.java:590)

In my opinion the problem is that
the org.apache.empire.db.DBTableColumn.validateNumber method uses a
different algorithm to extract the scale and precision from the supplied
datatype.

Thanks,
Ivan