开发者

SQlite Trigger Execution Problem

I'm new to Android & SQlite. I was trying to create the following trigger on an SQLite database in Android.

final String CREATE_TRIGGER_STATES = 
            "CREATE TRIGGER fk_insert_state BEFORE "
            + "INSERT on tbl_states"
            + "FOR EACH ROW "
            + "BEGIN "
            + "SELECT RAISE(ROLLBACK, 'insert on table "
            + "\"tbl_states\" violates foreign key constraint "
            + "\"fk_insert_state\"') WHERE (SELECT id FROM "
            + "tbl_countries WHERE id = NEW.country_id) IS NULL; "
            + "END;";
        db.execSQL(CREATE_TRIGGER_STATES);

Error log:

开发者_高级运维
android.database.sqlite.SQLiteException: near "EACH": syntax error: CREATE TRIGGER fk_insert_state BEFORE INSERT on tbl_statesFOR EACH ROW BEGIN SELECT RAISE(ROLLBACK, 'insert on table "tbl_states" violates foreign key constraint "fk_insert_state"') WHERE (SELECT id FROM tbl_countries WHERE id = NEW.country_id) IS NULL; END;

Is there a problem with the syntax ?


I'm guessing that the relevant portion of the error message is right here:

... on tbl_statesFOR EACH ROW ...
//--------------^^

You're missing a space after tbl_states:

final String CREATE_TRIGGER_STATES = 
            "CREATE TRIGGER fk_insert_state BEFORE "
            + "INSERT on tbl_states " // Missing space added
            //... Continue on as before.


You forgot a space:

 + "INSERT on tbl_states "    // Space missing here
 + "FOR EACH ROW "
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜