blob: de87a75b921910849e0c66ef58bc8817d0add424 [file] [log] [blame]
drh5974a302000-06-07 14:42:26 +00001# Copyright (c) 1999, 2000 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 02111-1307, USA.
17#
18# Author contact information:
19# drh@hwaci.com
20# http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library. The
24# focus of this file is testing the INSERT statement that takes is
25# result from a SELECT.
26#
27# $Id: insert2.test,v 1.1 2000/06/07 14:42:27 drh Exp $
28
29set testdir [file dirname $argv0]
30source $testdir/tester.tcl
31
32# Create some tables with data that we can select against
33#
34do_test insert2-1.0 {
35 execsql {CREATE TABLE d1(n int, log int);}
36 for {set i 1} {$i<=20} {incr i} {
37 for {set j 0} {pow(2,$j)<$i} {incr j} {}
38 execsql "INSERT INTO d1 VALUES($i,$j)"
39 }
40 execsql {SELECT * FROM d1 ORDER BY n}
41} {1 0 2 1 3 2 4 2 5 3 6 3 7 3 8 3 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 5 18 5 19 5 20 5}
42
43# Insert into a new table from the old one.
44#
45do_test insert2-1.1 {
46 execsql {
47 CREATE TABLE t1(log int, cnt int);
48 INSERT INTO t1 SELECT log, count(*) FROM d1 GROUP BY log;
49 }
50 execsql {SELECT * FROM t1 ORDER BY log}
51} {0 1 1 1 2 2 3 4 4 8 5 4}
52do_test insert2-1.2 {
53 catch {execsql {DROP TABLE t1}}
54 execsql {
55 CREATE TABLE t1(log int, cnt int);
56 INSERT INTO t1
57 SELECT log, count(*) FROM d1 GROUP BY log
58 EXCEPT SELECT n-1,log FROM d1;
59 SELECT * FROM t1 ORDER BY log;
60 }
61} {0 1 3 4 4 8 5 4}
62do_test insert2-1.3 {
63 catch {execsql {DROP TABLE t1}}
64 execsql {
65 CREATE TABLE t1(log int, cnt int);
66 INSERT INTO t1
67 SELECT log, count(*) FROM d1 GROUP BY log
68 INTERSECT SELECT n-1,log FROM d1;
69 SELECT * FROM t1 ORDER BY log;
70 }
71} {1 1 2 2}
72
73finish_test