How can I create a trigger between normal table and fts3 table?

雨燕双飞 提交于 2019-12-07 05:16:08

问题


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

回答1:


I think option for "external content" table is only available for FTS4 and not for FTS3.

External Content FTS4 Tables

Try using FTS4 table instead of FTS3.



来源:https://stackoverflow.com/questions/14886499/how-can-i-create-a-trigger-between-normal-table-and-fts3-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!