如何使用 rawquery 在 Room Library 中创建 table?
How to create table in Room Library using rawquery?
我在之前的申请中使用了sqlite
来创建数据库。现在我想使用 Room library
创建一个新应用程序。我有超过 100 个表的问题。我是否必须使用 @Entity
注释对所有表在 class 中一一声明我的所有表?我可以像我在 sqlite
中所做的那样使用 rawquery
制作表格和插入内容,例如:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS APP_VERSION(
ID INTEGER PRIMARY KEY,
LAST_UPDATE TEXT");
}
我可以像这样使用 rawquery
插入:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
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 :
没有。或者,更重要的是,Room 只会妨碍您执行此操作。
because I got the rawquery for create table from webservice
Room 适用于普通 Android 应用程序,您在编译时知道您的 table 定义并可以为它们编写 Java/Kotlin 类(实体、DAO、 RoomDatabase
、@ForeignKey
等)。
如果您在编译时不知道自己的 table 定义,则需要直接使用 SQLite 或查找其他不需要数据库模式编译时知识的库。
我在之前的申请中使用了sqlite
来创建数据库。现在我想使用 Room library
创建一个新应用程序。我有超过 100 个表的问题。我是否必须使用 @Entity
注释对所有表在 class 中一一声明我的所有表?我可以像我在 sqlite
中所做的那样使用 rawquery
制作表格和插入内容,例如:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS APP_VERSION(
ID INTEGER PRIMARY KEY,
LAST_UPDATE TEXT");
}
我可以像这样使用 rawquery
插入:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
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 :
没有。或者,更重要的是,Room 只会妨碍您执行此操作。
because I got the rawquery for create table from webservice
Room 适用于普通 Android 应用程序,您在编译时知道您的 table 定义并可以为它们编写 Java/Kotlin 类(实体、DAO、 RoomDatabase
、@ForeignKey
等)。
如果您在编译时不知道自己的 table 定义,则需要直接使用 SQLite 或查找其他不需要数据库模式编译时知识的库。