humazed/RoomAsset

Mapping Pre-populated database with column type NUMERIC

Closed this issue · 5 comments

Hello,

I have a pre-populated database with a column type NUMERIC and it seems that I cannot find an appropriated java type to map it. Just wonder how do I define my entity class to map this column?

This is the create statement:

CREATE TABLE function01tree (
fun_order NUMERIC,
fun_type INTEGER,
fun_no INTEGER PRIMARY KEY,
fun_parent_no INTEGER,
fun_descript TEXT,
fun_level INTEGER)

Thanks for the great library

from this table it translates to java.math.BigDecimal

but it really depends on the data in your database. if all the data in this column are integers then use int, if they are double use double.

Thank you for the reply.

Actually the data in the column are just integers. I tried to use Integer but I got

java.lang.IllegalStateException: Migration didn't properly handle function01tree.
 Expected:
TableInfo{name='function01tree',columns={
    fun_descript=Column{name='fun_descript', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0},
    fun_level=Column{name='fun_level', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0},
    fun_order=Column{name='fun_order', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, 
    fun_no=Column{name='fun_no', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1}, 
    fun_parent_no=Column{name='fun_parent_no', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, 
    fun_type=Column{name='fun_type', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}}, 
    foreignKeys=[], indices=[]}
  Found:
TableInfo{name='function01tree', columns={
    fun_descript=Column{name='fun_descript', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, 
    fun_level=Column{name='fun_level', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, 
    fun_order=Column{name='fun_order', type='NUMERIC', affinity='1', notNull=false, primaryKeyPosition=0}, 
    fun_no=Column{name='fun_no', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1}, 
    fun_parent_no=Column{name='fun_parent_no', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, 
    fun_type=Column{name='fun_type', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}}, 
    foreignKeys=[], indices=[]}

If I use BigDecimal, I got Cannot figure out how to save this field into database. You can consider adding a type converter for it. Then I face the same problem that which data type I should convert to/from.

you can use double, or use sqlite browser to change the datatype to integer.

I use the sqlite browser to change the data type to integer then everything works.

Thank you for the support

You are welcome.