When my App gets installed for the first time, I create a database programmatically. Works fine so far. But when I want to add a trigger, I get an exception saying "syntax error near IF". The problem is, that I can not span the String over multiple lines in source code. So what can I do instead?
private void createTriggers(SQLiteDatabase database) {
final String triggerLocationArchived = "CREATE TRIGGER location_archived AFTER UPDATE ON location FOR EACH ROW BEGIN IF NEW.deleted <> OLD.deleted THEN UPDATE sector set sector.deleted = NEW.deleted WHERE sector.location = NEW._id; END IF; END;";
database.execSQL(triggerLocationArchived);
}
There are two tables: location and sector. Each has an INTEGER flag indicating if the row has been archived. So I want all children (sectors within a location) to be archived as well if the parent (the location) is archived.