3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to verify that ticket [7bbfb7d442] has been
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix tkt-7bbfb7d442
22 CREATE TABLE t1(a, b);
23 INSERT INTO t1 VALUES(1, 'one');
24 INSERT INTO t1 VALUES(2, 'two');
25 INSERT INTO t1 VALUES(3, 'three');
27 CREATE TABLE t2(c, d);
28 INSERT INTO t2 VALUES('one', 'I');
29 INSERT INTO t2 VALUES('two', 'II');
30 INSERT INTO t2 VALUES('three', 'III');
32 CREATE TABLE t3(t3_a PRIMARY KEY, t3_d);
33 CREATE TRIGGER t3t AFTER INSERT ON t3 WHEN new.t3_d IS NULL BEGIN
34 UPDATE t3 SET t3_d = (
36 (SELECT * FROM t2 WHERE (new.t3_a%2)=(rowid%2) LIMIT 10),
37 (SELECT * FROM t1 WHERE (new.t3_a%2)=(rowid%2) LIMIT 10)
38 WHERE a = new.t3_a AND b = c
39 ) WHERE t3_a = new.t3_a;
44 INSERT INTO t3(t3_a) VALUES(1);
45 INSERT INTO t3(t3_a) VALUES(2);
46 INSERT INTO t3(t3_a) VALUES(3);
50 do_execsql_test 1.3 { DELETE FROM t3 }
54 INSERT INTO t3(t3_a) SELECT 1 UNION SELECT 2 UNION SELECT 3;
61 #-------------------------------------------------------------------------
62 # The following test case - 2.* - is from the original bug report as
63 # posted to the mailing list.
66 CREATE TABLE InventoryControl (
67 InventoryControlId INTEGER PRIMARY KEY AUTOINCREMENT,
69 Variant INTEGER NOT NULL DEFAULT 0,
70 ControlDate DATE NOT NULL,
71 ControlState INTEGER NOT NULL DEFAULT -1,
72 DeliveredQty VARCHAR(30)
75 CREATE TRIGGER TGR_InventoryControl_AfterInsert
76 AFTER INSERT ON InventoryControl
77 FOR EACH ROW WHEN NEW.ControlState=-1 BEGIN
79 INSERT OR REPLACE INTO InventoryControl(
80 InventoryControlId,SKU,Variant,ControlDate,ControlState,DeliveredQty
82 T1.InventoryControlId AS InventoryControlId,
84 T1.Variant AS Variant,
85 T1.ControlDate AS ControlDate,
87 COALESCE(T2.DeliveredQty,0) AS DeliveredQty
90 NEW.InventoryControlId AS InventoryControlId,
92 II.Variant AS Variant,
93 COALESCE(LastClosedIC.ControlDate,NEW.ControlDate) AS ControlDate
97 InventoryControl LastClosedIC
98 ON LastClosedIC.InventoryControlId IN ( SELECT 99999 )
101 II.Variant=NEW.Variant
106 TD.Variant AS Variant,
112 TD.Variant=NEW.Variant
115 T2.Variant=T1.Variant;
118 CREATE TABLE InventoryItem (
119 SKU INTEGER NOT NULL,
120 Variant INTEGER NOT NULL DEFAULT 0,
121 DeptCode INTEGER NOT NULL,
122 GroupCode INTEGER NOT NULL,
123 ItemDescription VARCHAR(120) NOT NULL,
124 PRIMARY KEY(SKU, Variant)
127 INSERT INTO InventoryItem VALUES(220,0,1,170,'Scoth Tampon Recurer');
128 INSERT INTO InventoryItem VALUES(31,0,1,110,'Fromage');
130 CREATE TABLE TransactionDetail (
131 TransactionId INTEGER NOT NULL,
132 SKU INTEGER NOT NULL,
133 Variant INTEGER NOT NULL DEFAULT 0,
134 PRIMARY KEY(TransactionId, SKU, Variant)
136 INSERT INTO TransactionDetail(TransactionId, SKU, Variant) VALUES(44, 31, 0);
139 INSERT INTO InventoryControl(SKU, Variant, ControlDate) SELECT
140 II.SKU AS SKU, II.Variant AS Variant, '2011-08-30' AS ControlDate
141 FROM InventoryItem II;
144 do_execsql_test 2.2 {
145 SELECT SKU, DeliveredQty FROM InventoryControl WHERE SKU=31
148 do_execsql_test 2.3 {
149 SELECT CASE WHEN DeliveredQty=10 THEN 'TEST PASSED!' ELSE 'TEST FAILED!' END
150 FROM InventoryControl WHERE SKU=31;