treasuredb/schema/triggers/checkIBANatTransfer.sql
Florian "flowdy" Heß 5299966837 Changed FAIL -> ABORT trigger exceptions
With FAIL, triggers choke but leave the changes in despite. We need to have the current statement undone, however.
2017-02-22 21:58:47 +01:00

14 lines
353 B
SQL

CREATE TRIGGER checkIBANatTransfer
BEFORE INSERT ON Debit
WHEN NEW.targetCredit IS NULL
BEGIN
SELECT RAISE(ABORT, "IBAN used does not match IBAN currently stored in account record")
FROM (
SELECT instr(NEW.purpose, IBAN) AS fnd
FROM Account
WHERE ID=NEW.debtor
) AS matchingIBAN
WHERE fnd IS NULL OR fnd = 0;
END;