Suspend Trigger via conditional

3

I did not find a SQL statenment IF in SQLite and the closest was CASE , which is answering me, however I would like to suspend a trigger with a conditional and I believe it can only be done with IF / p>

CREATE TRIGGER...
BEGIN
    IF (SELECT COUNT(*) FROM DATA < 900) THEN
       SUSPEND;

    ...
END;

Is it possible to do something like this in SQLite?

    
asked by anonymous 03.04.2018 / 23:08

2 answers

1
CREATE TRIGGER ...
AFTER UPDATE ON table WHEN NEW.field = 1
BEGIN
    ...
END

Can also be done with more than one conditional:

CREATE TRIGGER ...
AFTER UPDATE ON table WHEN NEW.field = 1 AND (SELECT COUNT(*) FROM table) >= 900
BEGIN
    ...
END
    
03.04.2018 / 23:42
1

For generic SQL, you can use CASE: CASE is used to provide% of logic type with% of SQL. Its syntax is:

SELECT CASE ("column_name")
  WHEN "condition1" THEN "result1"
  WHEN "condition2" THEN "result2"
  ...
  [ELSE "resultN"]
  END
FROM "table_name"

Example:

UPDATE pages
SET rkey = rkey + 2,
    lkey = CASE  WHEN lkey >= $key THEN lkey + 2 ELSE lkey END
WHERE rkey >= $key

Documentation link: Here

Other links that explain well: sqlite.awardspace.info and "Using CASE expressions when modifying data"

    
04.04.2018 / 15:53