我正在开发一个字典应用程序,它使用 FTS 表提供搜索。定义来自一个预打包的数据库,它具有以下模式:(.schema
Linux 上 sqlite3 程序的输出)
sqlite> .open words.db
sqlite> .schema
CREATE TABLE entries
(id INTEGER PRIMARY KEY NOT NULL,
word TEXT NOT NULL COLLATE NOCASE,
wordtype TEXT NOT NULL COLLATE NOCASE,
definition TEXT NOT NULL COLLATE NOCASE);
CREATE INDEX words_index ON entries(id, word);
CREATE VIRTUAL TABLE entriesFts USING FTS4(content='entries', word)
/* entriesFts(word) */;
CREATE TABLE IF NOT EXISTS 'entriesFts_segments'(blockid INTEGER PRIMARY KEY, block BLOB);
CREATE TABLE IF NOT EXISTS 'entriesFts_segdir'(level INTEGER,idx INTEGER,start_block INTEGER,leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));
CREATE TABLE IF NOT EXISTS 'entriesFts_docsize'(docid INTEGER PRIMARY KEY, size BLOB);
CREATE TABLE IF NOT EXISTS 'entriesFts_stat'(id INTEGER PRIMARY KEY, value BLOB);
我的实体定义如下所示:
@Entity(tableName="entries",
indices = [Index(name = "words_index", value = ["id", "word"])])
data class Word (
@PrimaryKey val id :Int,
@ColumnInfo val word :String,
@ColumnInfo(name = "wordtype") val wordType :String,
@ColumnInfo val definition :String
)
/* Used when displaying list of words */
@Fts4(contentEntity = Word::class)
@Entity(tableName = "entriesFts")
data class WordMinimal (
@PrimaryKey @ColumnInfo(name = "rowid") val id :Int,
@ColumnInfo val word :String
)
在我看来,模式完全匹配,但 Room 有不同的意见:/
它在 logcat 中抛出此错误:
java.lang.IllegalStateException: Pre-packaged database has an invalid schema: entriesFts(rawderm.dictionary.en.db.WordMinimal).
Expected:
FtsTableInfo{name='entriesFts', columns=[word], options=[content=`entries`]}
Found:
FtsTableInfo{name='entriesFts', columns=[word], options=[content='entries']}