blob: 616610bd4ba2f88c8ecdefc2a34f9e25d023312b [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
23if {$tcl_platform(platform)=="windows"} {
24 set CLI "sqlite3.exe"
25} else {
26 set CLI "./sqlite3"
shanehac81cd72009-11-10 17:07:30 +000027}
drh8df91852012-04-24 12:46:05 +000028if {![file executable $CLI]} {
29 finish_test
30 return
shanehac81cd72009-11-10 17:07:30 +000031}
drh8df91852012-04-24 12:46:05 +000032db close
33forcedelete test.db test.db-journal test.db-wal
shanehac81cd72009-11-10 17:07:30 +000034sqlite3 db test.db
35
36
37#----------------------------------------------------------------------------
38# shell2-1.*: Misc. test of various tickets and reported errors.
39#
40
41# Batch mode not creating databases.
shaneh5fc25012009-11-11 04:17:07 +000042# Reported on mailing list by Ken Zalewski.
shanehac81cd72009-11-10 17:07:30 +000043# Ticket [aeff892c57].
44do_test shell2-1.1.1 {
mistachkin9ac99312013-09-13 23:26:47 +000045 forcedelete foo.db
shaneh5fc25012009-11-11 04:17:07 +000046 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
shanehac81cd72009-11-10 17:07:30 +000047 set fexist [file exist foo.db]
48 list $rc $fexist
49} {{0 {}} 1}
50
shaneh5fc25012009-11-11 04:17:07 +000051# Shell silently ignores extra parameters.
52# Ticket [f5cb008a65].
53do_test shell2-1.2.1 {
54 set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
drhac5649a2014-11-28 13:35:03 +000055 list $rc $msg
56} {0 {3
574}}
shaneh5fc25012009-11-11 04:17:07 +000058
dan4564ced2010-01-05 04:59:56 +000059# Test a problem reported on the mailing list. The shell was at one point
60# returning the generic SQLITE_ERROR message ("SQL error or missing database")
61# instead of the "too many levels..." message in the test below.
62#
63do_test shell2-1.3 {
64 catchcmd "-batch test.db" {
65 PRAGMA recursive_triggers = ON;
66 CREATE TABLE t5(a PRIMARY KEY, b, c);
67 INSERT INTO t5 VALUES(1, 2, 3);
68 CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
69 UPDATE OR IGNORE t5 SET a = new.a, c = 10;
70 END;
71
72 UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
73 }
74} {1 {Error: near line 9: too many levels of trigger recursion}}
shanehca7dfda2009-12-17 21:07:54 +000075
shaneh5fc25012009-11-11 04:17:07 +000076
shanehb7977c52010-01-18 18:17:10 +000077
78# Shell not echoing all commands with echo on.
79# Ticket [eb620916be].
80
81# Test with echo off
82# NB. whitespace is important
83do_test shell2-1.4.1 {
mistachkin9ac99312013-09-13 23:26:47 +000084 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +000085 catchcmd "foo.db" {CREATE TABLE foo(a);
86INSERT INTO foo(a) VALUES(1);
87SELECT * FROM foo;}
88} {0 1}
89
90# Test with echo on using command line option
91# NB. whitespace is important
92do_test shell2-1.4.2 {
mistachkin9ac99312013-09-13 23:26:47 +000093 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +000094 catchcmd "-echo foo.db" {CREATE TABLE foo(a);
95INSERT INTO foo(a) VALUES(1);
96SELECT * FROM foo;}
97} {0 {CREATE TABLE foo(a);
98INSERT INTO foo(a) VALUES(1);
99SELECT * FROM foo;
1001}}
101
102# Test with echo on using dot command
103# NB. whitespace is important
104do_test shell2-1.4.3 {
mistachkin9ac99312013-09-13 23:26:47 +0000105 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +0000106 catchcmd "foo.db" {.echo ON
107CREATE TABLE foo(a);
108INSERT INTO foo(a) VALUES(1);
109SELECT * FROM foo;}
110} {0 {CREATE TABLE foo(a);
111INSERT INTO foo(a) VALUES(1);
112SELECT * FROM foo;
1131}}
114
115# Test with echo on using dot command and
116# turning off mid- processing.
117# NB. whitespace is important
118do_test shell2-1.4.4 {
mistachkin9ac99312013-09-13 23:26:47 +0000119 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +0000120 catchcmd "foo.db" {.echo ON
121CREATE TABLE foo(a);
122.echo OFF
123INSERT INTO foo(a) VALUES(1);
124SELECT * FROM foo;}
125} {0 {CREATE TABLE foo(a);
126.echo OFF
1271}}
128
129# Test with echo on using dot command and
130# multiple commands per line.
131# NB. whitespace is important
132do_test shell2-1.4.5 {
mistachkin9ac99312013-09-13 23:26:47 +0000133 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +0000134 catchcmd "foo.db" {.echo ON
135CREATE TABLE foo1(a);
136INSERT INTO foo1(a) VALUES(1);
137CREATE TABLE foo2(b);
138INSERT INTO foo2(b) VALUES(1);
139SELECT * FROM foo1; SELECT * FROM foo2;
140INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
141SELECT * FROM foo1; SELECT * FROM foo2;
142}
143} {0 {CREATE TABLE foo1(a);
144INSERT INTO foo1(a) VALUES(1);
145CREATE TABLE foo2(b);
146INSERT INTO foo2(b) VALUES(1);
147SELECT * FROM foo1;
1481
149SELECT * FROM foo2;
1501
151INSERT INTO foo1(a) VALUES(2);
152INSERT INTO foo2(b) VALUES(2);
153SELECT * FROM foo1;
1541
1552
156SELECT * FROM foo2;
1571
drh849a9d92013-12-21 15:46:06 +00001582
159}}
shanehb7977c52010-01-18 18:17:10 +0000160
161# Test with echo on and headers on using dot command and
162# multiple commands per line.
163# NB. whitespace is important
164do_test shell2-1.4.6 {
mistachkin9ac99312013-09-13 23:26:47 +0000165 forcedelete foo.db
shanehb7977c52010-01-18 18:17:10 +0000166 catchcmd "foo.db" {.echo ON
167.headers ON
168CREATE TABLE foo1(a);
169INSERT INTO foo1(a) VALUES(1);
170CREATE TABLE foo2(b);
171INSERT INTO foo2(b) VALUES(1);
172SELECT * FROM foo1; SELECT * FROM foo2;
173INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
174SELECT * FROM foo1; SELECT * FROM foo2;
175}
176} {0 {.headers ON
177CREATE TABLE foo1(a);
178INSERT INTO foo1(a) VALUES(1);
179CREATE TABLE foo2(b);
180INSERT INTO foo2(b) VALUES(1);
181SELECT * FROM foo1;
182a
1831
184SELECT * FROM foo2;
185b
1861
187INSERT INTO foo1(a) VALUES(2);
188INSERT INTO foo2(b) VALUES(2);
189SELECT * FROM foo1;
190a
1911
1922
193SELECT * FROM foo2;
194b
1951
drh849a9d92013-12-21 15:46:06 +00001962
197}}
drh74bec6b2010-07-19 15:01:43 +0000198
drh8df91852012-04-24 12:46:05 +0000199finish_test