Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping Pre-populated database with column type NUMERIC #15

Closed
cac-william opened this issue Aug 23, 2018 · 5 comments
Closed

Mapping Pre-populated database with column type NUMERIC #15

cac-william opened this issue Aug 23, 2018 · 5 comments

Comments

@cac-william
Copy link

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

@humazed
Copy link
Owner

humazed commented Aug 23, 2018

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.

@cac-william
Copy link
Author

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.

@humazed
Copy link
Owner

humazed commented Aug 23, 2018

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

@cac-william
Copy link
Author

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

Thank you for the support

@humazed
Copy link
Owner

humazed commented Aug 23, 2018

You are welcome.

@humazed humazed closed this as completed Aug 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants