xref: /sqlite-3.40.0/test/trigger5.test (revision b7f9164e)
100afe0b3Sdrh# The author disclaims copyright to this source code.  In place of
200afe0b3Sdrh# a legal notice, here is a blessing:
300afe0b3Sdrh#
400afe0b3Sdrh#    May you do good and not evil.
500afe0b3Sdrh#    May you find forgiveness for yourself and forgive others.
600afe0b3Sdrh#    May you share freely, never taking more than you give.
700afe0b3Sdrh#
800afe0b3Sdrh#***********************************************************************
900afe0b3Sdrh#
1000afe0b3Sdrh# This file tests the triggers of views.
1100afe0b3Sdrh#
1200afe0b3Sdrh
1300afe0b3Sdrhset testdir [file dirname $argv0]
1400afe0b3Sdrhsource $testdir/tester.tcl
15*b7f9164eSdrhifcapable {!trigger} {
16*b7f9164eSdrh  finish_test
17*b7f9164eSdrh  return
18*b7f9164eSdrh}
1900afe0b3Sdrh
2000afe0b3Sdrh# Ticket #844
2100afe0b3Sdrh#
2200afe0b3Sdrhdo_test trigger5-1.1 {
2300afe0b3Sdrh  execsql {
2400afe0b3Sdrh    CREATE TABLE Item(
2500afe0b3Sdrh       a integer PRIMARY KEY NOT NULL ,
2600afe0b3Sdrh       b double NULL ,
2700afe0b3Sdrh       c int NOT NULL DEFAULT 0
2800afe0b3Sdrh    );
2900afe0b3Sdrh    CREATE TABLE Undo(UndoAction TEXT);
3000afe0b3Sdrh    INSERT INTO Item VALUES (1,38205.60865,340);
3100afe0b3Sdrh    CREATE TRIGGER trigItem_UNDO_AD AFTER DELETE ON Item FOR EACH ROW
3200afe0b3Sdrh    BEGIN
3300afe0b3Sdrh      INSERT INTO Undo SELECT 'INSERT INTO Item (a,b,c) VALUES ('
3400afe0b3Sdrh       || coalesce(old.a,'NULL') || ',' || quote(old.b) || ',' || old.c || ');';
3500afe0b3Sdrh    END;
3600afe0b3Sdrh    DELETE FROM Item WHERE a = 1;
3700afe0b3Sdrh    SELECT * FROM Undo;
3800afe0b3Sdrh  }
3900afe0b3Sdrh} {{INSERT INTO Item (a,b,c) VALUES (1,38205.60865,340);}}
4000afe0b3Sdrh
4100afe0b3Sdrhintegrity_check trigger5-99.9
4200afe0b3Sdrh
4300afe0b3Sdrhfinish_test
44