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 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, ...);










share|improve this question




















  • 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 the rawquery for create table from webservice
    – 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 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

















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 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, ...);










share|improve this question




















  • 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 the rawquery for create table from webservice
    – 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 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















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 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, ...);










share|improve this question















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, ...);







java android sqlite android-room






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 using rawquery? because I got the rawquery for create table from webservice
    – 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 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
















  • 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 the rawquery for create table from webservice
    – 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 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










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














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.






share|improve this answer





















  • 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










  • 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













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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.






share|improve this answer





















  • 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










  • 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

















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.






share|improve this answer





















  • 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










  • 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















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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 12:48









CommonsWare

760k13718501904




760k13718501904












  • 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










  • 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










  • @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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma