5

I have been having issues switching between FTS3 tables and normal database tables. My application is very simple and allows the user to add contacts to a database and they can search for contacts that match the search query (why i used a fts table) and the result is then displayed on a list with an onItemclicklistener. But when I click the item, i get an error. I have traced this error back to the database (if I use normal database it works, but if I use fts it doesn't). So I have decided to use both types of databases and was wondering if someone could show me how a trigger is created to sync databases.

My first database is CONTACT (database name) and the table is called CONTACTS. The second database table is CONTACTS_FTS. All I am searching for is the COL_NAME, so is that all I need in my CONTACTS_FTS table? I was wondering if someone could check to see if my trigger is valid?

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;";
4

1 回答 1

0

我认为“外部内容”表的选项仅适用于 FTS4,不适用于 FTS3。

外部内容 FTS4 表

尝试使用 FTS4 表而不是 FTS3。

于 2015-05-04T14:54:25.870 回答