How to create table in Room Library using rawquery?
up vote
0
down vote
favorite
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 rawquery
like 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, ...);
java android sqlite android-room
|
show 2 more comments
up vote
0
down vote
favorite
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 rawquery
like 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, ...);
java android sqlite android-room
1
yes, you need 100+@Entity
classes
– pskink
Nov 11 at 12:42
@pskink wow... that will give me a lot of effort. there is no way I can usingrawquery
? because I got therawquery
forcreate
table fromwebservice
– Menma
Nov 11 at 12:45
1
so what do youu need 100+ tables for?
– pskink
Nov 11 at 12:46
@pskink so that's mean for large database, is it better to usesqlite
thanroom
? and for the insert query itself means it can't userawquery
?
– Menma
Nov 11 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 at 12:59
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 rawquery
like 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, ...);
java android sqlite android-room
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 rawquery
like 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, ...);
java android sqlite android-room
java android sqlite android-room
edited Nov 11 at 14:37
asked Nov 11 at 12:38
Menma
4911729
4911729
1
yes, you need 100+@Entity
classes
– pskink
Nov 11 at 12:42
@pskink wow... that will give me a lot of effort. there is no way I can usingrawquery
? because I got therawquery
forcreate
table fromwebservice
– Menma
Nov 11 at 12:45
1
so what do youu need 100+ tables for?
– pskink
Nov 11 at 12:46
@pskink so that's mean for large database, is it better to usesqlite
thanroom
? and for the insert query itself means it can't userawquery
?
– Menma
Nov 11 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 at 12:59
|
show 2 more comments
1
yes, you need 100+@Entity
classes
– pskink
Nov 11 at 12:42
@pskink wow... that will give me a lot of effort. there is no way I can usingrawquery
? because I got therawquery
forcreate
table fromwebservice
– Menma
Nov 11 at 12:45
1
so what do youu need 100+ tables for?
– pskink
Nov 11 at 12:46
@pskink so that's mean for large database, is it better to usesqlite
thanroom
? and for the insert query itself means it can't userawquery
?
– Menma
Nov 11 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 at 12:59
1
1
yes, you need 100+
@Entity
classes– pskink
Nov 11 at 12:42
yes, you need 100+
@Entity
classes– pskink
Nov 11 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 at 12:45
@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 at 12:45
1
1
so what do youu need 100+ tables for?
– pskink
Nov 11 at 12:46
so what do youu need 100+ tables for?
– pskink
Nov 11 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 at 12:57
@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 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 at 12:59
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 at 12:59
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
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.
that's mean for large database, is it better to usesqlite
thanroom
? and for theinsert
query itself means it can't userawquery
?
– Menma
Nov 11 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 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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
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.
that's mean for large database, is it better to usesqlite
thanroom
? and for theinsert
query itself means it can't userawquery
?
– Menma
Nov 11 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 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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
add a comment |
up vote
2
down vote
accepted
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.
that's mean for large database, is it better to usesqlite
thanroom
? and for theinsert
query itself means it can't userawquery
?
– Menma
Nov 11 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 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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
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.
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.
answered Nov 11 at 12:48
CommonsWare
760k13718501904
760k13718501904
that's mean for large database, is it better to usesqlite
thanroom
? and for theinsert
query itself means it can't userawquery
?
– Menma
Nov 11 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 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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
add a comment |
that's mean for large database, is it better to usesqlite
thanroom
? and for theinsert
query itself means it can't userawquery
?
– Menma
Nov 11 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 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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
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 at 12:53
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 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 at 13:10
@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 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 at 14:11
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 at 14:11
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
@CommonsWare i have spent 2 days but not found a solution yet, can you please help me here.
– shashank chandak
Nov 12 at 18:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248837%2fhow-to-create-table-in-room-library-using-rawquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
yes, you need 100+
@Entity
classes– pskink
Nov 11 at 12:42
@pskink wow... that will give me a lot of effort. there is no way I can using
rawquery
? because I got therawquery
forcreate
table fromwebservice
– Menma
Nov 11 at 12:45
1
so what do youu need 100+ tables for?
– pskink
Nov 11 at 12:46
@pskink so that's mean for large database, is it better to use
sqlite
thanroom
? and for the insert query itself means it can't userawquery
?– Menma
Nov 11 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 at 12:59