2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the INSERT statement that takes is
2N/A# result from a SELECT.
2N/Aset testdir [file dirname $argv0]
2N/A# Create some tables with data that we can select against
2N/Ado_test insert2-1.0 {
2N/A execsql {CREATE TABLE d1(n int, log int);}
2N/A for {set i 1} {$i<=20} {incr i} {
2N/A for {set j 0} {pow(2,$j)<$i} {incr j} {}
2N/A execsql "INSERT INTO d1 VALUES($i,$j)"
2N/A execsql {SELECT * FROM d1 ORDER BY n}
2N/A} {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}
2N/A# Insert into a new table from the old one.
2N/Ado_test insert2-1.1.1 {
2N/A CREATE TABLE t1(log int, cnt int);
2N/A PRAGMA count_changes=on;
2N/A INSERT INTO t1 SELECT log, count(*) FROM d1 GROUP BY log;
2N/Ado_test insert2-1.1.2 {
2N/Ado_test insert2-1.1.3 {
2N/A execsql {SELECT * FROM t1 ORDER BY log}
2N/A} {0 1 1 1 2 2 3 4 4 8 5 4}
2N/Ado_test insert2-1.2.1 {
2N/A catch {execsql {DROP TABLE t1}}
2N/A CREATE TABLE t1(log int, cnt int);
2N/A SELECT log, count(*) FROM d1 GROUP BY log
2N/A EXCEPT SELECT n-1,log FROM d1;
2N/Ado_test insert2-1.2.2 {
2N/A SELECT * FROM t1 ORDER BY log;
2N/Ado_test insert2-1.3.1 {
2N/A catch {execsql {DROP TABLE t1}}
2N/A CREATE TABLE t1(log int, cnt int);
2N/A PRAGMA count_changes=off;
2N/A SELECT log, count(*) FROM d1 GROUP BY log
2N/A INTERSECT SELECT n-1,log FROM d1;
2N/Ado_test insert2-1.3.2 {
2N/A SELECT * FROM t1 ORDER BY log;
2N/Ado_test insert2-1.4 {
2N/A catch {execsql {DROP TABLE t1}}
2N/A CREATE TABLE t1(log int, cnt int);
2N/A CREATE INDEX i1 ON t1(log);
2N/A CREATE INDEX i2 ON t1(cnt);
2N/A INSERT INTO t1 SELECT log, count() FROM d1 GROUP BY log;
2N/A SELECT * FROM t1 ORDER BY log;
2N/A lappend r [execsql {SELECT cnt FROM t1 WHERE log=3}]
2N/A lappend r [execsql {SELECT log FROM t1 WHERE cnt=4 ORDER BY log}]
2N/A} {0 1 1 1 2 2 3 4 4 8 5 4 4 {3 5}}
2N/Ado_test insert2-2.0 {
2N/A CREATE TABLE t3(a,b,c);
2N/A CREATE TABLE t4(x,y);
2N/A INSERT INTO t4 VALUES(1,2);
2N/Ado_test insert2-2.1 {
2N/A INSERT INTO t3(a,c) SELECT * FROM t4;
2N/Ado_test insert2-2.2 {
2N/A INSERT INTO t3(c,b) SELECT * FROM t4;
2N/Ado_test insert2-2.3 {
2N/A INSERT INTO t3(c,a,b) SELECT x, 'hi', y FROM t4;
2N/Aintegrity_check insert2-3.0
2N/A# File table t4 with lots of data
2N/Ado_test insert2-3.1 {
2N/Ado_test insert2-3.2 {
2N/A INSERT INTO t4 VALUES(2,4);
2N/A INSERT INTO t4 VALUES(3,6);
2N/A INSERT INTO t4 VALUES(4,8);
2N/A INSERT INTO t4 VALUES(5,10);
2N/A INSERT INTO t4 VALUES(6,12);
2N/A INSERT INTO t4 VALUES(7,14);
2N/A INSERT INTO t4 VALUES(8,16);
2N/A INSERT INTO t4 VALUES(9,18);
2N/A INSERT INTO t4 VALUES(10,20);
2N/Ado_test insert2-3.2.1 {
2N/A SELECT count(*) FROM t4;
2N/Ado_test insert2-3.3 {
2N/A INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
2N/A INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
2N/A INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
2N/A INSERT INTO t4 SELECT x+(SELECT max(x) FROM t4),y FROM t4;
2N/A SELECT count(*) FROM t4;
2N/Ado_test insert2-3.4 {
2N/A UPDATE t4 SET y='lots of data for the row where x=' || x
2N/A || ' and y=' || y || ' - even more data to fill space';
2N/A SELECT count(*) FROM t4;
2N/Ado_test insert2-3.5 {
2N/A INSERT INTO t4 SELECT x+(SELECT max(x)+1 FROM t4),y FROM t4;
2N/A SELECT count(*) from t4;
2N/Ado_test insert2-3.6 {
2N/A SELECT count(*) FROM t4;
2N/Ado_test insert2-3.7 {
2N/A DELETE FROM t4 WHERE x!=123;
2N/A SELECT count(*) FROM t4;
2N/Ado_test insert2-3.8 {
2N/Aintegrity_check insert2-3.9