(based on:
Android Room: One database with multiple tables
and
https://gist.github.com/garcia-pedro-hr/9bb5d286d3ea226234a04109d93d020a)
I have a .db file with multiple tables and I cannot wrap my mind around how to implement that into any applications, am I supposed to create an entity for every table in the .db file? even though every table consists of exact columns?
example:
table 'b' (
`Id` int(6) UNSIGNED NOT NULL,
`Short` text COLLATE utf8_unicode_ci DEFAULT NULL,
`Full_name` text COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(the information listed above I got from "mySQL workbench")
and a piece of data from table 'b':
(6, 'BBI', 'pow. bie.'),
table 'c'(
`Id` int(6) UNSIGNED NOT NULL,
`Short` text COLLATE utf8_unicode_ci DEFAULT NULL,
`Full_name` text COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
and a piece of data from table 'c':
(3, 'CT', 'Tor.'),
Yes
, although you could do one of the following to simplify matters :-
combine all the tables adding a column that indicates the table from the original. You could use the prePackagedDatabaseCallback to combine the tables (or pre-pare the pre-packaged database acccordingly).
use a single base class and extend that class e.g.
:-
and :-
and :-
With the class annotated with @Database including TableB and TableC in the list of entities e.g. :-
Room generates a class the same name as the class annotated with @Database but suffixed with _Impl which amongst other things has a method named createAllTables which using the above would be :-
UNICODE/UTF
note you may well have to check out your collation requirements (Room doesn't appear to say much about the UNICODE option) but you may find the following useful in this respect :-
https://sqlite.org/version3.html (see Support for UTF-8 and UTF-16)
https://sqlite.org/pragma.html#pragma_encoding
https://www.sqlite.org/datatype3.html#collation
https://developer.android.com/reference/androidx/room/ColumnInfo#summary