作者:爱的甜蜜日记2010 | 来源:互联网 | 2023-01-07 00:26
我正在寻找如何从普通的Sqlite迁移现有应用程序到Room,我无法找到如何迁移使用FTS的部件.
现在,我有一个虚拟表,每次插入或更新一行时都会被触发器填充:
private static final String CREATE_VIRTUAL_TABLE = "CREATE VIRTUAL TABLE " + FTS_VIRTUAL_TABLE +
" using fts4 (cOntent='" + TABLE_NOTIFICATION + "', " + COLUMN_TITLE + ")";
private static void createVirtualTriggers(SQLiteDatabase database){
database.execSQL("CREATE TRIGGER virtual_bu BEFORE UPDATE ON " + TABLE_NOTIFICATION + " BEGIN\n" + " DELETE FROM " + FTS_VIRTUAL_TABLE + " WHERE docid=old.rowid;\n" + "END;");
database.execSQL("CREATE TRIGGER virtual_bd BEFORE DELETE ON " + TABLE_NOTIFICATION + " BEGIN\n" + " DELETE FROM " + FTS_VIRTUAL_TABLE + " WHERE docid=old.rowid;\n" + "END;");
database.execSQL("CREATE TRIGGER virtual_au AFTER UPDATE ON " + TABLE_NOTIFICATION + " BEGIN\n" + " INSERT INTO " + FTS_VIRTUAL_TABLE + "(docid, " + COLUMN_TITLE + ") VALUES(new.rowid, new." + COLUMN_TITLE +");\n" + "END;");
database.execSQL("CREATE TRIGGER virtual_ai AFTER INSERT ON " + TABLE_NOTIFICATION + " BEGIN\n" + " INSERT INTO " + FTS_VIRTUAL_TABLE + "(docid, " + COLUMN_TITLE + ") VALUES(new.rowid, new." + COLUMN_TITLE +");\n" + "END;");
}
有没有办法与Room实现相同的功能?
1> CommonsWare..:
并不是的.请参阅此问题以及跟踪此请求的此问题.
您可以直接与数据库进行FTS方案,如创建表总是工作,并触发在这个问题您的代码段,通过调用getOpenHelper()
上RoomDatabase
,并用它相似SQLiteOpenHelper
.房间将忽略您在其背后创建的新表和内容.因此,如果您的FTS工作恰好与其他数据库工作完全分开,那么您可能会走这条路.