1# 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# 21set testdir [file dirname $argv0] 22source $testdir/tester.tcl 23if {$tcl_platform(platform)=="windows"} { 24 set CLI "sqlite3.exe" 25} else { 26 set CLI "./sqlite3" 27} 28if {![file executable $CLI]} { 29 finish_test 30 return 31} 32db close 33forcedelete test.db test.db-journal test.db-wal 34sqlite3 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. 42# Reported on mailing list by Ken Zalewski. 43# Ticket [aeff892c57]. 44do_test shell2-1.1.1 { 45 file delete -force foo.db 46 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ] 47 set fexist [file exist foo.db] 48 list $rc $fexist 49} {{0 {}} 1} 50 51# 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] 55 list $rc \ 56 [regexp {Error: too many options: "select 4"} $msg] 57} {1 1} 58 59# 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}} 75 76 77 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 { 84 file delete -force foo.db 85 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 { 93 file delete -force foo.db 94 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 { 105 file delete -force foo.db 106 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 { 119 file delete -force foo.db 120 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 { 133 file delete -force foo.db 134 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 1582}} 159 160# Test with echo on and headers on using dot command and 161# multiple commands per line. 162# NB. whitespace is important 163do_test shell2-1.4.6 { 164 file delete -force foo.db 165 catchcmd "foo.db" {.echo ON 166.headers ON 167CREATE TABLE foo1(a); 168INSERT INTO foo1(a) VALUES(1); 169CREATE TABLE foo2(b); 170INSERT INTO foo2(b) VALUES(1); 171SELECT * FROM foo1; SELECT * FROM foo2; 172INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2); 173SELECT * FROM foo1; SELECT * FROM foo2; 174} 175} {0 {.headers ON 176CREATE TABLE foo1(a); 177INSERT INTO foo1(a) VALUES(1); 178CREATE TABLE foo2(b); 179INSERT INTO foo2(b) VALUES(1); 180SELECT * FROM foo1; 181a 1821 183SELECT * FROM foo2; 184b 1851 186INSERT INTO foo1(a) VALUES(2); 187INSERT INTO foo2(b) VALUES(2); 188SELECT * FROM foo1; 189a 1901 1912 192SELECT * FROM foo2; 193b 1941 1952}} 196 197finish_test 198