xref: /sqlite-3.40.0/test/rowvalue8.test (revision 12abf408)
1*12abf408Sdrh# 2016-08-22
2*12abf408Sdrh#
3*12abf408Sdrh# The author disclaims copyright to this source code.  In place of
4*12abf408Sdrh# a legal notice, here is a blessing:
5*12abf408Sdrh#
6*12abf408Sdrh#    May you do good and not evil.
7*12abf408Sdrh#    May you find forgiveness for yourself and forgive others.
8*12abf408Sdrh#    May you share freely, never taking more than you give.
9*12abf408Sdrh#
10*12abf408Sdrh#***********************************************************************
11*12abf408Sdrh# Use of row values in CASE statements.
12*12abf408Sdrh#
13*12abf408Sdrh
14*12abf408Sdrhset testdir [file dirname $argv0]
15*12abf408Sdrhsource $testdir/tester.tcl
16*12abf408Sdrhset ::testprefix rowvalue8
17*12abf408Sdrh
18*12abf408Sdrhdo_execsql_test 1.1 {
19*12abf408Sdrh  CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
20*12abf408Sdrh  INSERT INTO t1(a,b,c,d) VALUES
21*12abf408Sdrh     (1,1,2,3),
22*12abf408Sdrh     (2,2,3,4),
23*12abf408Sdrh     (3,1,2,4),
24*12abf408Sdrh     (4,2,3,5),
25*12abf408Sdrh     (5,3,4,6),
26*12abf408Sdrh     (6,4,5,9);
27*12abf408Sdrh  SELECT a, CASE (b,c) WHEN (1,2) THEN 'aleph'
28*12abf408Sdrh                       WHEN (2,3) THEN 'bet'
29*12abf408Sdrh                       WHEN (3,4) THEN 'gimel'
30*12abf408Sdrh                       ELSE '-' END,
31*12abf408Sdrh         '|'
32*12abf408Sdrh    FROM t1
33*12abf408Sdrh   ORDER BY a;
34*12abf408Sdrh} {1 aleph | 2 bet | 3 aleph | 4 bet | 5 gimel | 6 - |}
35*12abf408Sdrhdo_execsql_test 1.2 {
36*12abf408Sdrh  SELECT a, CASE (b,c,d) WHEN (1,2,3) THEN 'aleph'
37*12abf408Sdrh                         WHEN (2,3,4) THEN 'bet'
38*12abf408Sdrh                         WHEN (3,4,6) THEN 'gimel'
39*12abf408Sdrh                         ELSE '-' END,
40*12abf408Sdrh         '|'
41*12abf408Sdrh    FROM t1
42*12abf408Sdrh   ORDER BY a;
43*12abf408Sdrh} {1 aleph | 2 bet | 3 - | 4 - | 5 gimel | 6 - |}
44*12abf408Sdrh
45*12abf408Sdrhdo_execsql_test 2.1 {
46*12abf408Sdrh  CREATE TABLE t2(x INTEGER PRIMARY KEY, y);
47*12abf408Sdrh  INSERT INTO t2(x,y) VALUES(1,6),(2,5),(3,4),(4,3),(5,2),(6,1);
48*12abf408Sdrh  SELECT x, CASE (SELECT b,c FROM t1 WHERE a=y)
49*12abf408Sdrh            WHEN (1,2) THEN 'aleph'
50*12abf408Sdrh            WHEN (2,3) THEN 'bet'
51*12abf408Sdrh            WHEN (3,4) THEN 'gimel'
52*12abf408Sdrh            ELSE '-' END,
53*12abf408Sdrh         '|'
54*12abf408Sdrh    FROM t2
55*12abf408Sdrh   ORDER BY +x;
56*12abf408Sdrh} {1 - | 2 gimel | 3 bet | 4 aleph | 5 bet | 6 aleph |}
57*12abf408Sdrh
58*12abf408Sdrh
59*12abf408Sdrhfinish_test
60