xref: /sqlite-3.40.0/test/select7.test (revision 4dcbdbff)
1# The author disclaims copyright to this source code.  In place of
2# a legal notice, here is a blessing:
3#
4#    May you do good and not evil.
5#    May you find forgiveness for yourself and forgive others.
6#    May you share freely, never taking more than you give.
7#
8#***********************************************************************
9# This file implements regression tests for SQLite library.  The
10# focus of this file is testing compute SELECT statements and nested
11# views.
12#
13# $Id: select7.test,v 1.7 2005/03/29 03:11:00 danielk1977 Exp $
14
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19ifcapable compound {
20
21# A 3-way INTERSECT.  Ticket #875
22ifcapable tempdb {
23  do_test select7-1.1 {
24    execsql {
25      create temp table t1(x);
26      insert into t1 values('amx');
27      insert into t1 values('anx');
28      insert into t1 values('amy');
29      insert into t1 values('bmy');
30      select * from t1 where x like 'a__'
31        intersect select * from t1 where x like '_m_'
32        intersect select * from t1 where x like '__x';
33    }
34  } {amx}
35}
36
37
38# Nested views do not handle * properly.  Ticket #826.
39#
40ifcapable view {
41do_test select7-2.1 {
42  execsql {
43    CREATE TABLE x(id integer primary key, a TEXT NULL);
44    INSERT INTO x (a) VALUES ('first');
45    CREATE TABLE tempx(id integer primary key, a TEXT NULL);
46    INSERT INTO tempx (a) VALUES ('t-first');
47    CREATE VIEW tv1 AS SELECT x.id, tx.id FROM x JOIN tempx tx ON tx.id=x.id;
48    CREATE VIEW tv1b AS SELECT x.id, tx.id FROM x JOIN tempx tx on tx.id=x.id;
49    CREATE VIEW tv2 AS SELECT * FROM tv1 UNION SELECT * FROM tv1b;
50    SELECT * FROM tv2;
51  }
52} {1 1}
53} ;# ifcapable view
54
55} ;# ifcapable compound
56
57# Do not allow GROUP BY without an aggregate. Ticket #1039.
58#
59# Change: force any query with a GROUP BY clause to be processed as
60# an aggregate query, whether it contains aggregates or not.
61#
62ifcapable subquery {
63  # do_test select7-3.1 {
64  #   catchsql {
65  #     SELECT * FROM (SELECT * FROM sqlite_master) GROUP BY name
66  #   }
67  # } {1 {GROUP BY may only be used on aggregate queries}}
68  do_test select7-3.1 {
69    catchsql {
70      SELECT * FROM (SELECT * FROM sqlite_master) GROUP BY name
71    }
72  } [list 0 [execsql {SELECT * FROM sqlite_master ORDER BY name}]]
73}
74finish_test
75
76