File: tkt2767.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (115 lines) | stat: -rwxr-xr-x 3,605 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(4)

--!./tcltestrunner.lua
-- 2007 Oct 3
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
--    May you do good and not evil.
--    May you find forgiveness for yourself and forgive others.
--    May you share freely, never taking more than you give.
--
-------------------------------------------------------------------------
--
-- This file is to test that ticket #2767 has been fixed.
-- Ticket #2767 is for a VDBE stack overflow on BEFORE
-- triggers that run RAISE(IGNORE).
--
-- $Id: tkt2767.test,v 1.3 2009/04/07 14:14:23 danielk1977 Exp $
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]


-- MUST_WORK_TEST
if (1 > 0)
 then
    test:do_execsql_test(
        "tkt2767-1.1",
        [[
            -- Construct a table with many rows of data
            CREATE TABLE t1(id INT PRIMARY KEY AUTOINCREMENT, x INT UNIQUE);
            INSERT INTO t1 VALUES(1, 1);
            INSERT INTO t1 VALUES(2, 2);
            INSERT INTO t1 (x) SELECT x+2 FROM t1;
            INSERT INTO t1 (x) SELECT x+4 FROM t1;
            INSERT INTO t1 (x) SELECT x+8 FROM t1;
            INSERT INTO t1 (x) SELECT x+16 FROM t1;

            -- BEFORE triggers that invoke raise(ignore).  The effect of
            -- these triggers should be to make INSERTs, UPDATEs, and DELETEs
            -- into no-ops.
            CREATE TRIGGER r1 BEFORE UPDATE ON t1 FOR EACH ROW
            BEGIN
              SELECT raise(ignore);
            END;
            CREATE TRIGGER r2 BEFORE DELETE ON t1 FOR EACH ROW
            BEGIN
              SELECT raise(ignore);
            END;
            CREATE TRIGGER r3 BEFORE INSERT ON t1 FOR EACH ROW
            BEGIN
              SELECT raise(ignore);
            END;

            -- Verify the table content
            SELECT count(*), sum(x) FROM t1;
        ]], {
            -- <tkt2767-1.1>
            32, 528
            -- </tkt2767-1.1>
        })

    -- Try to delete all elements of the table.  This will invoke the
    -- DELETE trigger 32 times, which should overflow the VDBE stack if
    -- the problem of #2767 is not fixed.  If the problem is fixed, all
    -- the deletes should be no-ops so the table should remain unchanged.
    --
    test:do_execsql_test(
        "tkt2767-1.2",
        [[
            DELETE FROM t1 WHERE x>0;
            SELECT count(*), sum(x) FROM t1;
        ]], {
            -- <tkt2767-1.2>
            32, 528
            -- </tkt2767-1.2>
        })

    -- Try to update all elements of the table.  This will invoke the
    -- UPDATE trigger 32 times, which should overflow the VDBE stack if
    -- the problem of #2767 is not fixed.  If the problem is fixed, all
    -- the updates should be no-ops so the table should remain unchanged.
    --
    test:do_execsql_test(
        "tkt2767-1.3",
        [[
            UPDATE t1 SET x=x+1;
            SELECT count(*), sum(x) FROM t1;
        ]], {
            -- <tkt2767-1.3>
            32, 528
            -- </tkt2767-1.3>
        })

    -- Invoke the insert trigger.  The insert trigger was working
    -- even prior to the fix of #2767.  But it seems good to go ahead
    -- and verify that it works.
    --
    test:do_execsql_test(
        "tkt2767-1.4",
        [[
            INSERT INTO t1 (x) SELECT x+32 FROM t1;
            SELECT count(*), sum(x) FROM t1;
        ]], {
            -- <tkt2767-1.4>
            32, 528
            -- </tkt2767-1.4>
        })

end
test:finish_test()