persistentstorage/sqlite3api/TEST/TclScript/tkt2767.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 # 2007 Oct 3
       
     2 #
       
     3 # The author disclaims copyright to this source code. In place of
       
     4 # a legal notice, here is a blessing:
       
     5 #
       
     6 #    May you do good and not evil.
       
     7 #    May you find forgiveness for yourself and forgive others.
       
     8 #    May you share freely, never taking more than you give.
       
     9 #
       
    10 #***********************************************************************
       
    11 #
       
    12 # This file is to test that ticket #2767 has been fixed.
       
    13 # Ticket #2767 is for a VDBE stack overflow on BEFORE
       
    14 # triggers that run RAISE(IGNORE).
       
    15 #
       
    16 # $Id: tkt2767.test,v 1.2 2008/07/12 14:52:21 drh Exp $
       
    17 #
       
    18 
       
    19 set testdir [file dirname $argv0]
       
    20 source $testdir/tester.tcl
       
    21 
       
    22 do_test tkt2767-1.1 {
       
    23   execsql {
       
    24     -- Construct a table with many rows of data
       
    25     CREATE TABLE t1(x);
       
    26     INSERT INTO t1 VALUES(1);
       
    27     INSERT INTO t1 VALUES(2);
       
    28     INSERT INTO t1 SELECT x+2 FROM t1;
       
    29     INSERT INTO t1 SELECT x+4 FROM t1;
       
    30     INSERT INTO t1 SELECT x+8 FROM t1;
       
    31     INSERT INTO t1 SELECT x+16 FROM t1;
       
    32 
       
    33     -- BEFORE triggers that invoke raise(ignore).  The effect of
       
    34     -- these triggers should be to make INSERTs, UPDATEs, and DELETEs
       
    35     -- into no-ops.
       
    36     CREATE TRIGGER r1 BEFORE UPDATE ON t1 BEGIN
       
    37       SELECT raise(ignore);
       
    38     END;
       
    39     CREATE TRIGGER r2 BEFORE DELETE ON t1 BEGIN
       
    40       SELECT raise(ignore);
       
    41     END;
       
    42     CREATE TRIGGER r3 BEFORE INSERT ON t1 BEGIN
       
    43       SELECT raise(ignore);
       
    44     END;
       
    45 
       
    46     -- Verify the table content
       
    47     SELECT count(*), sum(x) FROM t1;
       
    48   }
       
    49 } {32 528}
       
    50 
       
    51 # Try to delete all elements of the table.  This will invoke the
       
    52 # DELETE trigger 32 times, which should overflow the VDBE stack if
       
    53 # the problem of #2767 is not fixed.  If the problem is fixed, all
       
    54 # the deletes should be no-ops so the table should remain unchanged.
       
    55 #
       
    56 do_test tkt2767-1.2 {
       
    57   execsql {
       
    58     DELETE FROM t1 WHERE x>0;
       
    59     SELECT count(*), sum(x) FROM t1;
       
    60   }
       
    61 } {32 528}
       
    62 
       
    63 # Try to update all elements of the table.  This will invoke the
       
    64 # UPDATE trigger 32 times, which should overflow the VDBE stack if
       
    65 # the problem of #2767 is not fixed.  If the problem is fixed, all
       
    66 # the updates should be no-ops so the table should remain unchanged.
       
    67 #
       
    68 do_test tkt2767-1.3 {
       
    69   execsql {
       
    70     UPDATE t1 SET x=x+1;
       
    71     SELECT count(*), sum(x) FROM t1;
       
    72   }
       
    73 } {32 528}
       
    74 
       
    75 # Invoke the insert trigger.  The insert trigger was working
       
    76 # even prior to the fix of #2767.  But it seems good to go ahead
       
    77 # and verify that it works.
       
    78 #
       
    79 do_test tkt2767-1.4 {
       
    80   execsql {
       
    81     INSERT INTO t1 SELECT x+32 FROM t1;
       
    82     SELECT count(*), sum(x) FROM t1;
       
    83   }
       
    84 } {32 528}
       
    85 
       
    86 
       
    87 
       
    88 finish_test