0

I used sqlite in my previous application to create a database. now I want to create a new application using Room library. I have a problem where I have more than 100 tables. do I have to declare all my tables in class one by one for all my tables using @Entity annotation? can I make tables and inserts use rawquerylike what I did in sqlite such as like this :

@Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE IF NOT EXISTS APP_VERSION( ID INTEGER PRIMARY KEY, LAST_UPDATE TEXT"); }

and can I using rawquery for insert like this : INSERT INTO table_name VALUES (value1, value2, value3, ...);

Menma
  • 799
  • 1
  • 9
  • 35
  • 1
    yes, you need 100+ `@Entity` classes – pskink Nov 11 '18 at 12:42
  • @pskink wow... that will give me a lot of effort. there is no way I can using `rawquery`? because I got the `rawquery` for `create` table from `webservice` – Menma Nov 11 '18 at 12:45
  • 1
    so what do youu need 100+ tables for? – pskink Nov 11 '18 at 12:46
  • @pskink so that's mean for large database, is it better to use `sqlite` than `room`? and for the insert query itself means it can't use `rawquery`? – Menma Nov 11 '18 at 12:57
  • cannot you redesign your tables? are you sure you need all those 100+ tables? aren't they redundant? what do you need them for? – pskink Nov 11 '18 at 12:59
  • @pskink sadly can't, I make a big application and it needs 100 tables on my application T.T, – Menma Nov 11 '18 at 13:08
  • @pskink at first I think there's another option for creating table without using `@entity`. but now I know there's no way except create it.... thank you for your help – Menma Nov 11 '18 at 14:10

1 Answers1

4

do I have to declare all my tables in class one by one for all my tables using @Entity annotation?

Yes.

can I make tables and inserts use rawquerylike what I did in sqlite such as like this :

No. Or, more to the point, Room will only get in the way of you doing this.

because I got the rawquery for create table from webservice

Room is for ordinary Android apps, where you know your table definitions at compile time and can write the Java/Kotlin classes for them (entities, DAOs, RoomDatabase, @ForeignKey, etc.).

If you do not know your table definitions at compile time, you will need to work with SQLite directly or find some other library that does not require compile-time knowledge of your database schema.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • that's mean for large database, is it better to use `sqlite` than `room`? and for the `insert` query itself means it can't use `rawquery`? – Menma Nov 11 '18 at 12:53
  • @Menma: "that's mean for large database, is it better to use sqlite than room?" -- not necessarily. Your problem is not that the database is large. Your problem is that you do not know your database structure at compile time, if you are downloading the database structure at runtime. For ~100 tables, you are going to need hundreds of classes -- Room does not change that. Or, if you think that you can manage ~100 tables with a few classes, you do not need ~100 tables. – CommonsWare Nov 11 '18 at 13:10
  • thank you for your explanation and your answer. I think I need to discuss with my team either using room or sqlite. thank you very much. – Menma Nov 11 '18 at 14:11
  • @CommonsWare i have spent 2 days but not found a solution yet, can you please help me [here](https://stackoverflow.com/questions/53241140/firebase-job-dispatcher-not-scheduling-jobs-on-oreo-devices). – shashank chandak Nov 12 '18 at 18:04