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 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this script is correct code generation of aliased result-set
14 # values. See ticket #3343.
16 # $Id: alias.test,v 1.3 2009/04/23 13:22:44 drh Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # Aliases are currently evaluated twice. We might try to change this
22 # in the future. But not now.
25 # A procedure to return a sequence of increasing integers.
27 namespace eval ::seq {
42 db function sequence ::seq::value
45 INSERT INTO t1 VALUES(9);
46 INSERT INTO t1 VALUES(8);
47 INSERT INTO t1 VALUES(7);
48 SELECT x, sequence() FROM t1;
54 SELECT x, sequence() AS y FROM t1 WHERE y>0
60 SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99
66 SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 AND y!=55
72 SELECT x, sequence() AS y FROM t1
73 WHERE y>0 AND y<99 AND y!=55 AND y NOT IN (56,57,58)
74 AND y NOT LIKE 'abc%' AND y%10==2
80 SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99
86 # SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3)
92 SELECT x, 1-sequence() AS y FROM t1 ORDER BY y
98 SELECT x, sequence() AS y FROM t1 ORDER BY -y
104 SELECT x, sequence() AS y FROM t1 ORDER BY x%2, y
108 unset -nocomplain random_int_list
109 set random_int_list [db eval {
110 SELECT random()&2147483647 AS r FROM t1, t1, t1, t1 ORDER BY r
113 lsort -integer $::random_int_list
119 SELECT 4 UNION SELECT 1 ORDER BY 1
124 SELECT 4 UNION SELECT 1 UNION SELECT 9 ORDER BY 1
129 # Aliases in the GROUP BY clause cause the expression to be evaluated
130 # twice in the current implementation. This might change in the future.
135 SELECT sequence(*) AS y, count(*) AS z FROM t1 GROUP BY y ORDER BY z, y