我想知道是否有人可以确认我正确创建了TRIGGER。我正在将普通表同步到FTS表,以便能够使用搜索。但我不能仅仅出于某种原因单独使用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;";