我在FTS3表和普通数据库表之间切换时遇到问题。我的应用程序非常简单,允许用户将联系人添加到数据库,他们可以搜索与搜索查询匹配的联系人(为什么我使用了fts表),然后结果显示在带有onItemclicklistener的列表中。但是当我点击该项目时,我收到一个错误。我已将此错误追溯到数据库(如果我使用普通数据库,它可以工作,但如果我使用fts则不然)。所以我决定使用这两种类型的数据库,并想知道是否有人可以告诉我如何创建触发器来同步数据库。
我的第一个数据库是CONTACT(数据库名称),该表名为CONTACTS。第二个数据库表是CONTACTS_FTS。我正在搜索的是COL_NAME,所以我在CONTACTS_FTS表中需要的是什么?我想知道是否有人可以查看我的触发器是否有效?
public static final String DATABASE_NAME = "CONTACT";
public static final String DATABASE_TABLE = "CONTACTS";
private static final String DATABASE_TABLE_FTS = "CONTACTS_FTS";
private static final int DATABASE_VERSION = 20;
private Context ourContext;
private DbHelper DBHelper;
private static SQLiteDatabase db;
private static final String DATABASE_CREATE =
"CREATE TABLE " + DATABASE_TABLE + " (" +
COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL_NAME + " TEXT NOT NULL, " +
COL_EMAIL + " TEXT NOT NULL, " +
COL_CELL + " TEXT NOT NULL, " +
COL_ARRIVAL + " TEXT NOT NULL, " +
COL_DEPARTURE + " TEXT NOT NULL, " +
COL_FLIGHT_NUMBER + " TEXT NOT NULL, " +
COL_HOTEL_ROOM_NUMBER + " TEXT NOT NULL, " +
COL_EVENT1 + " TEXT NOT NULL, " +
COL_EVENT2 + " TEXT NOT NULL, " +
COL_EVENT1_ROOM + " TEXT NOT NULL, " +
COL_EVENT2_ROOM + " TEXT NOT NULL);";
private static final String DATABASE_CREATE_FTS =
"CREATE VIRTUAL TABLE " + DATABASE_TABLE_FTS + " USING fts3(" +
"content=" + "\"CONTACTS\", " +
COL_NAME + ");";
private static final String Trigger =
"CREATE TRIGGER contacts_Trigger " +
"AFTER INSERT "+ "ON " + DATABASE_TABLE +
" BEGIN " +
"INSERT " + DATABASE_TABLE_FTS + " SET " + COL_NAME + " = new.COL_NAME WHERE " + COL_ID + " = old.COL_ID;" +
" END;";