Changed FAIL -> ABORT trigger exceptions
With FAIL, triggers choke but leave the changes in despite. We need to have the current statement undone, however.
This commit is contained in:
		
							parent
							
								
									f54f940f74
								
							
						
					
					
						commit
						5299966837
					
				@ -2,12 +2,12 @@ CREATE TRIGGER linkTransferTightly
 | 
			
		||||
    AFTER INSERT ON Transfer 
 | 
			
		||||
BEGIN
 | 
			
		||||
 | 
			
		||||
  SELECT RAISE(FAIL, "It is not the debtor who is set to pay")
 | 
			
		||||
  SELECT RAISE(ABORT, "It is not the debtor who is set to pay")
 | 
			
		||||
    WHERE (SELECT debtor FROM Debit WHERE billId=NEW.billId)
 | 
			
		||||
       != (SELECT account FROM Credit WHERE credId=NEW.credId)
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
  SELECT RAISE(FAIL, "Target of a debit cannot be an incoming payment")
 | 
			
		||||
  SELECT RAISE(ABORT, "Target of a debit cannot be an incoming payment")
 | 
			
		||||
  FROM Credit c
 | 
			
		||||
    JOIN Debit d ON c.credId = d.targetCredit
 | 
			
		||||
  WHERE c.credId = NEW.credId
 | 
			
		||||
@ -18,8 +18,8 @@ BEGIN
 | 
			
		||||
 | 
			
		||||
  INSERT INTO __INTERNAL_TRIGGER_STACK
 | 
			
		||||
      SELECT NEW.ROWID,
 | 
			
		||||
          CASE remainingDebt   WHEN 0 THEN RAISE(FAIL, "Debt settled") ELSE NEW.billId END,
 | 
			
		||||
          CASE remainingCredit WHEN 0 THEN RAISE(FAIL, "Credit spent") ELSE NEW.credId END,
 | 
			
		||||
          CASE remainingDebt   WHEN 0 THEN RAISE(ABORT, "Debt settled") ELSE NEW.billId END,
 | 
			
		||||
          CASE remainingCredit WHEN 0 THEN RAISE(ABORT, "Credit spent") ELSE NEW.credId END,
 | 
			
		||||
          min(remainingDebt, remainingCredit) 
 | 
			
		||||
      FROM (SELECT
 | 
			
		||||
          (SELECT value - paid FROM Debit WHERE billId=NEW.billId) AS remainingDebt, 
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ CREATE TRIGGER checkIBANatTransfer
 | 
			
		||||
    BEFORE INSERT ON Debit
 | 
			
		||||
    WHEN NEW.targetCredit IS NULL
 | 
			
		||||
BEGIN
 | 
			
		||||
   SELECT RAISE(FAIL, "IBAN used does not match IBAN currently stored in account record")
 | 
			
		||||
   SELECT RAISE(ABORT, "IBAN used does not match IBAN currently stored in account record")
 | 
			
		||||
   FROM (
 | 
			
		||||
      SELECT instr(NEW.purpose, IBAN) AS fnd
 | 
			
		||||
      FROM Account
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,6 @@ CREATE TRIGGER x_changedCredit
 | 
			
		||||
    WHEN EXISTS (SELECT * FROM Transfer WHERE credId=NEW.credId)
 | 
			
		||||
     AND NOT EXISTS (SELECT * FROM __INTERNAL_TRIGGER_STACK)
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "Credit involved in transactions to revoke at first");
 | 
			
		||||
    SELECT RAISE(ABORT, "Credit involved in transactions to revoke at first");
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,6 @@ CREATE TRIGGER x_changedDebit
 | 
			
		||||
    WHEN EXISTS (SELECT * FROM Transfer WHERE billId=NEW.billId)
 | 
			
		||||
     AND NOT EXISTS (SELECT * FROM __INTERNAL_TRIGGER_STACK LIMIT 1)
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "Debt is involved in transfers to revoke at first");
 | 
			
		||||
    SELECT RAISE(ABORT, "Debt is involved in transfers to revoke at first");
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,6 @@ CREATE TRIGGER x_changedTransfer
 | 
			
		||||
    WHEN OLD.amount IS NOT NULL
 | 
			
		||||
      AND NOT EXISTS (SELECT * FROM __INTERNAL_TRIGGER_STACK)
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "Transfer cannot be updated, but needs to be replaced to make triggers run");
 | 
			
		||||
    SELECT RAISE(ABORT, "Transfer cannot be updated, but needs to be replaced to make triggers run");
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,6 @@ CREATE TRIGGER x_paidChangedOutsideTrigger
 | 
			
		||||
    BEFORE UPDATE OF paid ON Debit
 | 
			
		||||
    WHEN NOT EXISTS (SELECT * FROM __INTERNAL_TRIGGER_STACK LIMIT 1)
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "paid is set and adjusted automatically according to added Transfer records");
 | 
			
		||||
    SELECT RAISE(ABORT, "paid is set and adjusted automatically according to added Transfer records");
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
CREATE TRIGGER x_paidFromBeginning
 | 
			
		||||
    BEFORE INSERT ON Debit
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "Debt must be initially unpaid")
 | 
			
		||||
    SELECT RAISE(ABORT, "Debt must be initially unpaid")
 | 
			
		||||
    WHERE NEW.paid <> 0;
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,6 @@ CREATE TRIGGER x_spentChangedOutsideTrigger
 | 
			
		||||
    BEFORE UPDATE OF spent ON Credit
 | 
			
		||||
    WHEN NOT EXISTS (SELECT * FROM __INTERNAL_TRIGGER_STACK)
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "spent is set and adjusted automatically according to added Transfer records");
 | 
			
		||||
    SELECT RAISE(ABORT, "spent is set and adjusted automatically according to added Transfer records");
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
CREATE TRIGGER x_spentFromBeginning
 | 
			
		||||
    BEFORE INSERT ON Credit
 | 
			
		||||
BEGIN
 | 
			
		||||
    SELECT RAISE(FAIL, "credit must be initially unused")
 | 
			
		||||
    SELECT RAISE(ABORT, "credit must be initially unused")
 | 
			
		||||
    WHERE NEW.spent != 0;
 | 
			
		||||
END;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user