xref: /sqlite-3.40.0/test/countofview.test (revision 73c53b39)
1a4b5fb55Sdan# 2018-08-04
2a4b5fb55Sdan#
3a4b5fb55Sdan# The author disclaims copyright to this source code.  In place of
4a4b5fb55Sdan# a legal notice, here is a blessing:
5a4b5fb55Sdan#
6a4b5fb55Sdan#    May you do good and not evil.
7a4b5fb55Sdan#    May you find forgiveness for yourself and forgive others.
8a4b5fb55Sdan#    May you share freely, never taking more than you give.
9a4b5fb55Sdan#
10a4b5fb55Sdan#***********************************************************************
11a4b5fb55Sdan#
12a4b5fb55Sdan#
13a4b5fb55Sdan
14a4b5fb55Sdanset testdir [file dirname $argv0]
15a4b5fb55Sdansource $testdir/tester.tcl
16a4b5fb55Sdansource $testdir/malloc_common.tcl
17a4b5fb55Sdanset testprefix countofview
18a4b5fb55Sdan
19a4b5fb55Sdando_execsql_test 1.0 {
20a4b5fb55Sdan  CREATE TABLE t2(c);
21a4b5fb55Sdan  CREATE TABLE t3(f);
22a4b5fb55Sdan
23a4b5fb55Sdan  INSERT INTO t2 VALUES(1), (2);
24a4b5fb55Sdan  INSERT INTO t3 VALUES(3);
25a4b5fb55Sdan}
26a4b5fb55Sdan
27a4b5fb55Sdando_execsql_test 1.1 {
28a4b5fb55Sdan  select c from t2 union all select f from t3 limit 1 offset 1
29a4b5fb55Sdan} {2}
30a4b5fb55Sdan
31a4b5fb55Sdando_execsql_test 1.2 {
32a4b5fb55Sdan  select count(*) from (
33a4b5fb55Sdan    select c from t2 union all select f from t3 limit 1 offset 1
34a4b5fb55Sdan  )
35a4b5fb55Sdan} {1}
36a4b5fb55Sdan
37a4b5fb55Sdando_execsql_test 1.3 {
38a4b5fb55Sdan  select count(*) from (
39a4b5fb55Sdan    select c from t2 union all select f from t3
40a4b5fb55Sdan  )
41a4b5fb55Sdan} {3}
42a4b5fb55Sdan
43*73c53b39Sdrh# 2019-05-15
44*73c53b39Sdrhdo_execsql_test 2.0 {
45*73c53b39Sdrh  CREATE TABLE t1(x);
46*73c53b39Sdrh  INSERT INTO t1 VALUES(1),(99),('abc');
47*73c53b39Sdrh  CREATE VIEW v1(x,y) AS SELECT x,1 FROM t1 UNION ALL SELECT x,2 FROM t1;
48*73c53b39Sdrh  SELECT count(*) FROM v1 WHERE x<>1;
49*73c53b39Sdrh} {4}
50*73c53b39Sdrhdo_execsql_test 2.1 {
51*73c53b39Sdrh  SELECT count(*) FROM v1 GROUP BY y;
52*73c53b39Sdrh} {3 3}
53*73c53b39Sdrh
54*73c53b39Sdrh
55*73c53b39Sdrh
56a4b5fb55Sdanfinish_test
57