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 #2192 has been
17 # $Id: tkt2192.test,v 1.3 2008/08/04 03:51:24 danielk1977 Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 ifcapable !datetime||!compound {
29 -- Raw data (RBS) --------
31 create table records (
40 -- Direct Debits ----------------
41 create view direct_debits as
42 select * from records where type = 'D/D';
44 create view monthly_direct_debits as
45 select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
47 group by strftime('%Y-%m', date);
49 -- Expense Categories ---------------
51 select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
53 where description like '%NPOWER%'
54 group by strftime('%Y-%m', date);
56 create view phone_internet as
57 select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
59 where description like '%BT DIRECT%'
60 or description like '%SUPANET%'
61 or description like '%ORANGE%'
62 group by strftime('%Y-%m', date);
64 create view credit_cards as
65 select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
66 from direct_debits where description like '%VISA%'
67 group by strftime('%Y-%m', date);
69 -- Overview ---------------------
71 create view expense_overview as
72 select 'Energy' as expense, date, value from energy
74 select 'Phone/Internet' as expense, date, value from phone_internet
76 select 'Credit Card' as expense, date, value from credit_cards;
79 select 'jan', expense, value from expense_overview
80 where date like '%-01';
83 select 'nov', expense, value from expense_overview
84 where date like '%-11';
86 create view summary as
87 select * from jan join nov on (jan.expense = nov.expense);
91 # set ::sqlite_addop_trace 1
93 select * from summary;
100 SELECT * FROM t1 WHERE b%7=0 UNION SELECT * FROM t1 WHERE b%5=0;
101 INSERT INTO t1 VALUES(1,7);
102 INSERT INTO t1 VALUES(2,10);
103 INSERT INTO t1 VALUES(3,14);
104 INSERT INTO t1 VALUES(4,15);
105 INSERT INTO t1 VALUES(1,16);
106 INSERT INTO t1 VALUES(2,17);
107 INSERT INTO t1 VALUES(3,20);
108 INSERT INTO t1 VALUES(4,21);
109 INSERT INTO t1 VALUES(1,22);
110 INSERT INTO t1 VALUES(2,24);
111 INSERT INTO t1 VALUES(3,25);
112 INSERT INTO t1 VALUES(4,26);
113 INSERT INTO t1 VALUES(1,27);
115 SELECT b FROM v1 ORDER BY b;
117 } {7 10 14 15 20 21 25}
118 do_test tkt2192-2.2 {
120 SELECT * FROM v1 ORDER BY a, b;
122 } {1 7 2 10 3 14 3 20 3 25 4 15 4 21}
123 do_test tkt2192-2.3 {
125 SELECT x.a || '/' || x.b || '/' || y.b
126 FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
127 ORDER BY x.a, x.b, y.b
129 } {3/14/20 3/14/25 3/20/25 4/15/21}
130 do_test tkt2192-2.4 {
133 SELECT x.a || '/' || x.b || '/' || y.b AS z
134 FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
135 ORDER BY x.a, x.b, y.b;
138 } {3/14/20 3/14/25 3/20/25 4/15/21}