blob: aba04a1490d1762b9047d9cc14db87312f7b630c [file] [log] [blame]
shanehac81cd72009-11-10 17:07:30 +00001# 2009 Nov 11
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11#
12# The focus of this file is testing the CLI shell tool.
13#
14# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
15#
16
17# Test plan:
18#
19# shell2-1.*: Misc. test of various tickets and reported errors.
20#
drh8df91852012-04-24 12:46:05 +000021set testdir [file dirname $argv0]
22source $testdir/tester.tcl
dan089555c2016-03-15 09:55:44 +000023set CLI [test_find_cli]
drh8df91852012-04-24 12:46:05 +000024db close
25forcedelete test.db test.db-journal test.db-wal
shanehac81cd72009-11-10 17:07:30 +000026sqlite3 db test.db
27
28
29#----------------------------------------------------------------------------
30# shell2-1.*: Misc. test of various tickets and reported errors.
31#
32
33# Batch mode not creating databases.
shaneh5fc25012009-11-11 04:17:07 +000034# Reported on mailing list by Ken Zalewski.
shanehac81cd72009-11-10 17:07:30 +000035# Ticket [aeff892c57].
36do_test shell2-1.1.1 {
mistachkin9ac99312013-09-13 23:26:47 +000037 forcedelete foo.db
shaneh5fc25012009-11-11 04:17:07 +000038 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
shanehac81cd72009-11-10 17:07:30 +000039 set fexist [file exist foo.db]
40 list $rc $fexist
41} {{0 {}} 1}
42
shaneh5fc25012009-11-11 04:17:07 +000043# Shell silently ignores extra parameters.
44# Ticket [f5cb008a65].
45do_test shell2-1.2.1 {
larrybr6b7e47f2021-09-19 18:31:55 +000046 catchcmdex {:memory: "select+3" "select+4"}
drhac5649a2014-11-28 13:35:03 +000047} {0 {3
larrybr6b7e47f2021-09-19 18:31:55 +0000484
49}}
shaneh5fc25012009-11-11 04:17:07 +000050
dan4564ced2010-01-05 04:59:56 +000051# 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.
54#
55do_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;
63
64 UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
65 }
drh633c7982022-02-08 12:13:16 +000066} {1 {Runtime error near line 9: too many levels of trigger recursion}}
shanehca7dfda2009-12-17 21:07:54 +000067
shaneh5fc25012009-11-11 04:17:07 +000068
shanehb7977c52010-01-18 18:17:10 +000069
70# Shell not echoing all commands with echo on.
71# Ticket [eb620916be].
72
73# Test with echo off
74# NB. whitespace is important
75do_test shell2-1.4.1 {
mistachkin9ac99312013-09-13 23:26:47 +000076 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +000077 catchcmd "foo.db" {CREATE TABLE foo(a);
78INSERT INTO foo(a) VALUES(1);
79SELECT * FROM foo;}
80} {0 1}
81
82# Test with echo on using command line option
83# NB. whitespace is important
84do_test shell2-1.4.2 {
mistachkin9ac99312013-09-13 23:26:47 +000085 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +000086 catchcmd "-echo foo.db" {CREATE TABLE foo(a);
87INSERT INTO foo(a) VALUES(1);
88SELECT * FROM foo;}
89} {0 {CREATE TABLE foo(a);
90INSERT INTO foo(a) VALUES(1);
91SELECT * FROM foo;
921}}
93
94# Test with echo on using dot command
95# NB. whitespace is important
96do_test shell2-1.4.3 {
mistachkin9ac99312013-09-13 23:26:47 +000097 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +000098 catchcmd "foo.db" {.echo ON
99CREATE TABLE foo(a);
100INSERT INTO foo(a) VALUES(1);
101SELECT * FROM foo;}
102} {0 {CREATE TABLE foo(a);
103INSERT INTO foo(a) VALUES(1);
104SELECT * FROM foo;
1051}}
106
107# Test with echo on using dot command and
108# turning off mid- processing.
109# NB. whitespace is important
110do_test shell2-1.4.4 {
mistachkin9ac99312013-09-13 23:26:47 +0000111 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +0000112 catchcmd "foo.db" {.echo ON
113CREATE TABLE foo(a);
114.echo OFF
115INSERT INTO foo(a) VALUES(1);
116SELECT * FROM foo;}
117} {0 {CREATE TABLE foo(a);
118.echo OFF
1191}}
120
121# Test with echo on using dot command and
122# multiple commands per line.
123# NB. whitespace is important
124do_test shell2-1.4.5 {
mistachkin9ac99312013-09-13 23:26:47 +0000125 forcedelete foo.db
larrybr6b7e47f2021-09-19 18:31:55 +0000126 catchcmdex "foo.db" {.echo ON
shanehb7977c52010-01-18 18:17:10 +0000127CREATE TABLE foo1(a);
128INSERT INTO foo1(a) VALUES(1);
129CREATE TABLE foo2(b);
130INSERT INTO foo2(b) VALUES(1);
131SELECT * FROM foo1; SELECT * FROM foo2;
132INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
133SELECT * FROM foo1; SELECT * FROM foo2;
134}
135} {0 {CREATE TABLE foo1(a);
136INSERT INTO foo1(a) VALUES(1);
137CREATE TABLE foo2(b);
138INSERT INTO foo2(b) VALUES(1);
larrybrf4874812022-05-11 19:59:31 +0000139SELECT * FROM foo1; SELECT * FROM foo2;
shanehb7977c52010-01-18 18:17:10 +00001401
shanehb7977c52010-01-18 18:17:10 +00001411
larrybrf4874812022-05-11 19:59:31 +0000142INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
143SELECT * FROM foo1; SELECT * FROM foo2;
shanehb7977c52010-01-18 18:17:10 +00001441
1452
shanehb7977c52010-01-18 18:17:10 +00001461
drh849a9d92013-12-21 15:46:06 +00001472
148}}
shanehb7977c52010-01-18 18:17:10 +0000149
150# Test with echo on and headers on using dot command and
151# multiple commands per line.
152# NB. whitespace is important
153do_test shell2-1.4.6 {
mistachkin9ac99312013-09-13 23:26:47 +0000154 forcedelete foo.db
larrybr6b7e47f2021-09-19 18:31:55 +0000155 catchcmdex "foo.db" {.echo ON
shanehb7977c52010-01-18 18:17:10 +0000156.headers ON
157CREATE TABLE foo1(a);
158INSERT INTO foo1(a) VALUES(1);
159CREATE TABLE foo2(b);
160INSERT INTO foo2(b) VALUES(1);
161SELECT * FROM foo1; SELECT * FROM foo2;
162INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
163SELECT * FROM foo1; SELECT * FROM foo2;
164}
165} {0 {.headers ON
166CREATE TABLE foo1(a);
167INSERT INTO foo1(a) VALUES(1);
168CREATE TABLE foo2(b);
169INSERT INTO foo2(b) VALUES(1);
larrybrf4874812022-05-11 19:59:31 +0000170SELECT * FROM foo1; SELECT * FROM foo2;
shanehb7977c52010-01-18 18:17:10 +0000171a
1721
shanehb7977c52010-01-18 18:17:10 +0000173b
1741
larrybrf4874812022-05-11 19:59:31 +0000175INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
176SELECT * FROM foo1; SELECT * FROM foo2;
shanehb7977c52010-01-18 18:17:10 +0000177a
1781
1792
shanehb7977c52010-01-18 18:17:10 +0000180b
1811
drh849a9d92013-12-21 15:46:06 +00001822
183}}
drh74bec6b2010-07-19 15:01:43 +0000184
larrybrc6e2f2e2022-03-15 17:57:42 +0000185# Test for rejection of incomplete input at EOF.
186# Reported at https://sqlite.org/forum/forumpost/718f489a43be3197
187do_test shell2-1.4.7 {
188 catchcmd ":memory:" {
189 SELECT 'unclosed;}
190} {1 {Parse error near line 2: unrecognized token: "'unclosed;"
191 SELECT 'unclosed;
192 ^--- error here}}
193
larrybr8af6d712022-12-04 23:20:38 +0000194# Verify that safe mode rejects certain UDFs
195# Reported at https://sqlite.org/forum/forumpost/07beac8056151b2f
196do_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}}
200do_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}}
204
larrybre8f114b2023-01-16 21:49:37 +0000205# Verify that .clone handles sequence table.
206# See https://sqlite.org/forum/forumpost/71ff9e6c4c
207do_test shell2-1.4.9 {
208 forcedelete clone.db
209 set res [catchcmd :memory: [string trim {
210 CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT);
211 INSERT INTO t VALUES (1),(2);
212.clone clone.db
213.open clone.db
214 SELECT max(seq) FROM sqlite_sequence;}]]
215} {0 {t... done
216done
2172}}
218
larrybr8af6d712022-12-04 23:20:38 +0000219
drh8df91852012-04-24 12:46:05 +0000220finish_test