Fixed
Status Update
Comments
yb...@google.com <yb...@google.com>
yb...@google.com <yb...@google.com> #2
I think it is best if we implement the following:
3.1. Determination Of Column Affinity
The affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
If the declared type contains the string "INT" then it is assigned INTEGER affinity.
If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.
If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
Otherwise, the affinity is NUMERIC.
Note that the order of the rules for determining column affinity is important. A column whose declared type is "CHARINT" will match both rules 1 and 2 but the first rule takes precedence and so the column affinity will be INTEGER.
3.1. Determination Of Column Affinity
The affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
If the declared type contains the string "INT" then it is assigned INTEGER affinity.
If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.
If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
Otherwise, the affinity is NUMERIC.
Note that the order of the rules for determining column affinity is important. A column whose declared type is "CHARINT" will match both rules 1 and 2 but the first rule takes precedence and so the column affinity will be INTEGER.
yb...@google.com <yb...@google.com>
sa...@gmail.com <sa...@gmail.com> #3
Can you please specify from which release this issue has been fixed? Thanks!
60...@gmail.com <60...@gmail.com> #5
I believe this is still an issue with Room 2.2.1? I am still getting issues like the following:
Expected:
TableInfo{name='planets', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, rebel_base_lat=Column{name='rebel_base_lat', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, rebel_base_lon=Column{name='rebel_base_lon', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='planets', columns={rebel_base_lat=Column{name='rebel_base_lat', type='decimal', affinity='1', notNull=false, primaryKeyPosition=0, defaultValue='null'}, name=Column{name='name', type='varchar(255)', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='integer', affinity='3', notNull=false, primaryKeyPosition=1, defaultValue='null'}, rebel_base_lng=Column{name='rebel_base_lng', type='decimal', affinity='1', notNull=false, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
Expected:
TableInfo{name='planets', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, rebel_base_lat=Column{name='rebel_base_lat', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, rebel_base_lon=Column{name='rebel_base_lon', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='planets', columns={rebel_base_lat=Column{name='rebel_base_lat', type='decimal', affinity='1', notNull=false, primaryKeyPosition=0, defaultValue='null'}, name=Column{name='name', type='varchar(255)', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='integer', affinity='3', notNull=false, primaryKeyPosition=1, defaultValue='null'}, rebel_base_lng=Column{name='rebel_base_lng', type='decimal', affinity='1', notNull=false, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
60...@gmail.com <60...@gmail.com> #6
I forgot to mention in the previous comment: this issue happens when using the "createFromAsset" functionality as described in [1]. I am trying to get the data from an existing sqlite database.
[1]https://medium.com/androiddevelopers/packing-the-room-pre-populate-your-database-with-this-one-method-333ae190e680
[1]
60...@gmail.com <60...@gmail.com> #7
My apologies for the misleading report. After debugging I found out that the reason was a typo in one of my columns plus the use of not nullable types in my Kotlin entity. This means that createFromAsset seems to work fine, but it necessary to make sure that the types, nullability and default values match.
Description
Version used: 1.0.0
Devices/Android versions reproduced on: any
When trying to upgrade an existing project with an existing database to use Room, a migration is needed if the types used are not one of the canonical Sqlite types. Sqlite, however, supports other types that have affinities to these existing types - for example, VARCHAR is has an affinity of TEXT, and DATE has an affinity of NUMERIC and so on. Please see here:
It would be awesome if a migration is not needed for existing database columns with these types and Room could just internally accept a VARCHAR as TEXT for example.