【发布时间】:2020-09-28 12:21:47
【问题描述】:
我按照 codelab 教程进行操作,结果感到困惑。我想使用外部数据库进行测试,唯一的一个表和列(word_table 和 word 如codelab中提到的)工作正常。但我正在尝试使用以下 sql 信息添加我自己创建的 .db:
CREATE TABLE "product_table" (
"id" INTEGER NOT NULL,
"product" TEXT,
"partof" TEXT,
PRIMARY KEY("id")
);
我不确定如何正确注释它。以下是我正在使用的代码。
WordDao.kt
@Dao
interface WordDao {
@Query("SELECT * from product_table ORDER BY id ASC")
fun getAlphabetizedId(): List<Id>
@Query("SELECT * from product_table ORDER BY word ASC")
fun getAlphabetizedWords(): LiveData<List<Word>>
@Query("SELECT * from product_table ORDER BY partof ASC")
fun getAlphabetizedPartof(): List<Partof>
Product.kt
@Entity(tableName = "eilian_table")
class Id(@PrimaryKey @ColumnInfo(name = "id") val id: String)
@Entity(tableName = "eilian_table")
class Word(@ColumnInfo(name = "word") val word: String)
@Entity(tableName = "eilian_table")
class Partof(@ColumnInfo(name = "partof") val partof: String)
获取符号和引用错误。
【问题讨论】:
标签: android-studio kotlin android-room dao