Small performance optimization in sqlite3VdbeRecordCompareWithSkip() for
[sqlite.git] / test / shell2.test
blob2de6bf7514201d7ff14d355a29ec751f2b265048
1 # 2009 Nov 11
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 # The focus of this file is testing the CLI shell tool.
14 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
17 # Test plan:
19 #   shell2-1.*: Misc. test of various tickets and reported errors.
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
23 set CLI [test_find_cli]
24 db close
25 forcedelete test.db test.db-journal test.db-wal
26 sqlite3 db test.db
29 #----------------------------------------------------------------------------
30 #   shell2-1.*: Misc. test of various tickets and reported errors.
33 # Batch mode not creating databases.  
34 # Reported on mailing list by Ken Zalewski.
35 # Ticket [aeff892c57].
36 do_test shell2-1.1.1 {
37   forcedelete foo.db
38   set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
39   set fexist [file exist foo.db]
40   list $rc $fexist
41 } {{0 {}} 1}
43 # Shell silently ignores extra parameters.
44 # Ticket [f5cb008a65].
45 do_test shell2-1.2.1 {
46   set rc [catch { eval exec $CLI \":memory:\" \"select+3\" \"select+4\" } msg]
47   list $rc $msg
48 } {0 {3
49 4}}
51 # Test a problem reported on the mailing list. The shell was at one point
52 # returning the generic SQLITE_ERROR message ("SQL error or missing database")
53 # instead of the "too many levels..." message in the test below.
55 do_test shell2-1.3 {
56   catchcmd "-batch test.db" {
57     PRAGMA recursive_triggers = ON;
58     CREATE TABLE t5(a PRIMARY KEY, b, c);
59     INSERT INTO t5 VALUES(1, 2, 3);
60     CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
61       UPDATE OR IGNORE t5 SET a = new.a, c = 10;
62     END;
64     UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
65   }
66 } {1 {Error: near line 9: too many levels of trigger recursion}}
70 # Shell not echoing all commands with echo on.
71 # Ticket [eb620916be].
73 # Test with echo off
74 # NB. whitespace is important
75 do_test shell2-1.4.1 {
76   forcedelete foo.db
77   catchcmd "foo.db" {CREATE TABLE foo(a);
78 INSERT INTO foo(a) VALUES(1);
79 SELECT * FROM foo;}
80 } {0 1}
82 # Test with echo on using command line option
83 # NB. whitespace is important
84 do_test shell2-1.4.2 {
85   forcedelete foo.db
86   catchcmd "-echo foo.db" {CREATE TABLE foo(a);
87 INSERT INTO foo(a) VALUES(1);
88 SELECT * FROM foo;}
89 } {0 {CREATE TABLE foo(a);
90 INSERT INTO foo(a) VALUES(1);
91 SELECT * FROM foo;
92 1}}
94 # Test with echo on using dot command
95 # NB. whitespace is important
96 do_test shell2-1.4.3 {
97   forcedelete foo.db
98   catchcmd "foo.db" {.echo ON
99 CREATE TABLE foo(a);
100 INSERT INTO foo(a) VALUES(1);
101 SELECT * FROM foo;}
102 } {0 {CREATE TABLE foo(a);
103 INSERT INTO foo(a) VALUES(1);
104 SELECT * FROM foo;
107 # Test with echo on using dot command and 
108 # turning off mid- processing.
109 # NB. whitespace is important
110 do_test shell2-1.4.4 {
111   forcedelete foo.db
112   catchcmd "foo.db" {.echo ON
113 CREATE TABLE foo(a);
114 .echo OFF
115 INSERT INTO foo(a) VALUES(1);
116 SELECT * FROM foo;}
117 } {0 {CREATE TABLE foo(a);
118 .echo OFF
121 # Test with echo on using dot command and 
122 # multiple commands per line.
123 # NB. whitespace is important
124 do_test shell2-1.4.5 {
125   forcedelete foo.db
126   catchcmd "foo.db" {.echo ON
127 CREATE TABLE foo1(a);
128 INSERT INTO foo1(a) VALUES(1);
129 CREATE TABLE foo2(b);
130 INSERT INTO foo2(b) VALUES(1);
131 SELECT * FROM foo1; SELECT * FROM foo2;
132 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
133 SELECT * FROM foo1; SELECT * FROM foo2;
135 } {0 {CREATE TABLE foo1(a);
136 INSERT INTO foo1(a) VALUES(1);
137 CREATE TABLE foo2(b);
138 INSERT INTO foo2(b) VALUES(1);
139 SELECT * FROM foo1;
141 SELECT * FROM foo2;
143 INSERT INTO foo1(a) VALUES(2);
144 INSERT INTO foo2(b) VALUES(2);
145 SELECT * FROM foo1;
148 SELECT * FROM foo2;
153 # Test with echo on and headers on using dot command and 
154 # multiple commands per line.
155 # NB. whitespace is important
156 do_test shell2-1.4.6 {
157   forcedelete foo.db
158   catchcmd "foo.db" {.echo ON
159 .headers ON
160 CREATE TABLE foo1(a);
161 INSERT INTO foo1(a) VALUES(1);
162 CREATE TABLE foo2(b);
163 INSERT INTO foo2(b) VALUES(1);
164 SELECT * FROM foo1; SELECT * FROM foo2;
165 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
166 SELECT * FROM foo1; SELECT * FROM foo2;
168 } {0 {.headers ON
169 CREATE TABLE foo1(a);
170 INSERT INTO foo1(a) VALUES(1);
171 CREATE TABLE foo2(b);
172 INSERT INTO foo2(b) VALUES(1);
173 SELECT * FROM foo1;
176 SELECT * FROM foo2;
179 INSERT INTO foo1(a) VALUES(2);
180 INSERT INTO foo2(b) VALUES(2);
181 SELECT * FROM foo1;
185 SELECT * FROM foo2;
191 finish_test