SQLITE触发器的多个条件

时间:2016-04-29 16:24:29

标签: android sqlite android-sqlite

如果在触发器上声明的当前表得到更新,我需要更新另一个表上的字段。但我需要在2个条件之后更新

    public class Match{
        public int participant1;
        public int participant2;
        public int winner;
        public boolean finalMatch;
        public int standingId;
    }

        public class Standings{
            public int id;
            public int firstPlace;
            public int SecondPlace;
        }

private static final String CREATE_TRIGGER_MATCH_UPDATE_BRACKET_WINNERS_F1 = "CREATE TRIGGER if not exists updatefields
        AFTER UPDATE OF  winner
            ON Match
            WHEN new.finalMatch = 1 AND new.winner = new.participant1
            BEGIN
            UPDATE Standings
                SET firstPlace = new.winner
                    SecondPlace = new.participant2
            WHERE id = new.standingId
        END;"

但这会引发错误。显然,只有" WHEN条件" for android上的触发器。现在我不确定如何检查它。正如我想在一个触发器上更新这两个字段。如果我做两个触发器,1用于设置" firstPlace"另一个用于" secondPlace",第二个将在Standings表上,我不确定如何访问#34; secondPlace"值。

1 个答案:

答案 0 :(得分:0)

修复语法(triggerupdate)错误后,接受触发器:

CREATE TRIGGER if not exists updatefields
AFTER UPDATE OF winner ON Match
WHEN new.finalMatch = 1 AND new.winner = new.participant1
BEGIN
    UPDATE Standings
    SET firstPlace  = new.winner,          -- comma here
        SecondPlace = new.participant2
    WHERE id = new.standingId;             -- semicolon here
END;