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 $
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]
25 forcedelete test.db test.db-journal test.db-wal
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 {
38 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
39 set fexist [file exist foo.db]
43 # Shell silently ignores extra parameters.
44 # Ticket [f5cb008a65].
45 do_test shell2-1.2.1 {
46 catchcmdex {:memory: "select+3" "select+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.
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;
64 UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
66 } {1 {Runtime error near line 9: too many levels of trigger recursion}}
70 # Shell not echoing all commands with echo on.
71 # Ticket [eb620916be].
74 # NB. whitespace is important
75 do_test shell2-1.4.1 {
77 catchcmd "foo.db" {CREATE TABLE foo(a);
78 INSERT INTO foo(a) VALUES(1);
82 # Test with echo on using command line option
83 # NB. whitespace is important
84 do_test shell2-1.4.2 {
86 catchcmd "-echo foo.db" {CREATE TABLE foo(a);
87 INSERT INTO foo(a) VALUES(1);
89 } {0 {CREATE TABLE foo(a);
90 INSERT INTO foo(a) VALUES(1);
94 # Test with echo on using dot command
95 # NB. whitespace is important
96 do_test shell2-1.4.3 {
98 catchcmd "foo.db" {.echo ON
100 INSERT INTO foo(a) VALUES(1);
102 } {0 {CREATE TABLE foo(a);
103 INSERT INTO foo(a) VALUES(1);
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 {
112 catchcmd "foo.db" {.echo ON
115 INSERT INTO foo(a) VALUES(1);
117 } {0 {CREATE TABLE foo(a);
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 {
126 catchcmdex "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; SELECT * FROM foo2;
142 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
143 SELECT * FROM foo1; SELECT * FROM foo2;
150 # Test with echo on and headers on using dot command and
151 # multiple commands per line.
152 # NB. whitespace is important
153 do_test shell2-1.4.6 {
155 catchcmdex "foo.db" {.echo ON
157 CREATE TABLE foo1(a);
158 INSERT INTO foo1(a) VALUES(1);
159 CREATE TABLE foo2(b);
160 INSERT INTO foo2(b) VALUES(1);
161 SELECT * FROM foo1; SELECT * FROM foo2;
162 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
163 SELECT * FROM foo1; SELECT * FROM foo2;
166 CREATE TABLE foo1(a);
167 INSERT INTO foo1(a) VALUES(1);
168 CREATE TABLE foo2(b);
169 INSERT INTO foo2(b) VALUES(1);
170 SELECT * FROM foo1; SELECT * FROM foo2;
175 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
176 SELECT * FROM foo1; SELECT * FROM foo2;
185 # Test for rejection of incomplete input at EOF.
186 # Reported at https://sqlite.org/forum/forumpost/718f489a43be3197
187 do_test shell2-1.4.7 {
188 catchcmd ":memory:" {
190 } {1 {Parse error near line 2: unrecognized token: "'unclosed;"
194 # Verify that safe mode rejects certain UDFs
195 # Reported at https://sqlite.org/forum/forumpost/07beac8056151b2f
196 do_test shell2-1.4.8 {
197 catchcmd "-safe :memory:" {
198 SELECT edit('DoNotCare');}
199 } {1 {line 2: cannot use the edit() function in safe mode}}
200 do_test shell2-1.4.9 {
201 catchcmd "-safe :memory:" {
202 SELECT writefile('DoNotCare', x'');}
203 } {1 {line 2: cannot use the writefile() function in safe mode}}
205 # Verify that .clone handles sequence table.
206 # See https://sqlite.org/forum/forumpost/71ff9e6c4c
207 do_test shell2-1.4.9 {
209 set res [catchcmd :memory: [string trim {
210 CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT);
211 INSERT INTO t VALUES (1),(2);
214 SELECT max(seq) FROM sqlite_sequence;}]]
219 # Verify that generate_series stays sane near 64-bit range boundaries.
220 # See overflow report at https://sqlite.org/forum/forumpost/5d34ce5280
221 do_test shell2-1.4.10 {
222 set res [catchcmd :memory: [string trim {
223 SELECT * FROM generate_series(9223372036854775807,9223372036854775807,1);
224 SELECT * FROM generate_series(9223372036854775807,9223372036854775807,-1);
225 SELECT avg(rowid),min(value),max(value) FROM generate_series(
226 -9223372036854775808,9223372036854775807,1085102592571150095);
227 SELECT * FROM generate_series(-9223372036854775808,9223372036854775807,
228 9223372036854775807);
229 SELECT value,rowid FROM generate_series(-4611686018427387904,
230 4611686018427387904, 4611686018427387904) ORDER BY value DESC;
231 SELECT * FROM generate_series(0,-2,-1);
232 SELECT * FROM generate_series(0,-2);
233 SELECT * FROM generate_series(0,2) LIMIT 3;}]]
234 } {0 {9223372036854775807
236 9.5|-9223372036854775808|9223372036854775807
240 4611686018427387904|3
242 -4611686018427387904|1
250 # Bug discovered while messing around, .import hangs with
251 # bit 7 set in column separator.
252 do_test shell2-1.4.11 {
253 forcedelete dummy.csv
254 set df [open dummy.csv w]
257 set res [catchcmd :memory: [string trim {
258 CREATE TABLE t(line text);
260 .separator "\377" "\n"
262 SELECT count(*) FROM t;}]]
265 # Bug from forum post 7cbe081746dd3803
266 # Keywords as column names were producing an error message.
267 do_test shell2-1.4.12 {
268 set res [catchcmd :memory: [string trim {
269 CREATE TABLE "group"("order" text);
270 INSERT INTO "group" VALUES ('ABC');
272 } {0 ca08bc02b7e95c7df431a3a4b1cc0f8d8743914793473f55b5558e03}