shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 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 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 21 | set testdir [file dirname $argv0] |
| 22 | source $testdir/tester.tcl |
dan | 089555c | 2016-03-15 09:55:44 +0000 | [diff] [blame] | 23 | set CLI [test_find_cli] |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 24 | db close |
| 25 | forcedelete test.db test.db-journal test.db-wal |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 26 | sqlite3 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. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 34 | # Reported on mailing list by Ken Zalewski. |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 35 | # Ticket [aeff892c57]. |
| 36 | do_test shell2-1.1.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 37 | forcedelete foo.db |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 38 | set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ] |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 39 | set fexist [file exist foo.db] |
| 40 | list $rc $fexist |
| 41 | } {{0 {}} 1} |
| 42 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 43 | # Shell silently ignores extra parameters. |
| 44 | # Ticket [f5cb008a65]. |
| 45 | do_test shell2-1.2.1 { |
larrybr | 6b7e47f | 2021-09-19 18:31:55 +0000 | [diff] [blame] | 46 | catchcmdex {:memory: "select+3" "select+4"} |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 47 | } {0 {3 |
larrybr | 6b7e47f | 2021-09-19 18:31:55 +0000 | [diff] [blame] | 48 | 4 |
| 49 | }} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 50 | |
dan | 4564ced | 2010-01-05 04:59:56 +0000 | [diff] [blame] | 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. |
| 54 | # |
| 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; |
| 63 | |
| 64 | UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1; |
| 65 | } |
drh | 633c798 | 2022-02-08 12:13:16 +0000 | [diff] [blame] | 66 | } {1 {Runtime error near line 9: too many levels of trigger recursion}} |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 67 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 68 | |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 69 | |
| 70 | # Shell not echoing all commands with echo on. |
| 71 | # Ticket [eb620916be]. |
| 72 | |
| 73 | # Test with echo off |
| 74 | # NB. whitespace is important |
| 75 | do_test shell2-1.4.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 76 | forcedelete foo.db |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 77 | catchcmd "foo.db" {CREATE TABLE foo(a); |
| 78 | INSERT INTO foo(a) VALUES(1); |
| 79 | SELECT * FROM foo;} |
| 80 | } {0 1} |
| 81 | |
| 82 | # Test with echo on using command line option |
| 83 | # NB. whitespace is important |
| 84 | do_test shell2-1.4.2 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 85 | forcedelete foo.db |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 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}} |
| 93 | |
| 94 | # Test with echo on using dot command |
| 95 | # NB. whitespace is important |
| 96 | do_test shell2-1.4.3 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 97 | forcedelete foo.db |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 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; |
| 105 | 1}} |
| 106 | |
| 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 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 111 | forcedelete foo.db |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 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 |
| 119 | 1}} |
| 120 | |
| 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 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 125 | forcedelete foo.db |
larrybr | 6b7e47f | 2021-09-19 18:31:55 +0000 | [diff] [blame] | 126 | catchcmdex "foo.db" {.echo ON |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 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; |
| 134 | } |
| 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); |
larrybr | f487481 | 2022-05-11 19:59:31 +0000 | [diff] [blame] | 139 | SELECT * FROM foo1; SELECT * FROM foo2; |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 140 | 1 |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 141 | 1 |
larrybr | f487481 | 2022-05-11 19:59:31 +0000 | [diff] [blame] | 142 | INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2); |
| 143 | SELECT * FROM foo1; SELECT * FROM foo2; |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 144 | 1 |
| 145 | 2 |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 146 | 1 |
drh | 849a9d9 | 2013-12-21 15:46:06 +0000 | [diff] [blame] | 147 | 2 |
| 148 | }} |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 149 | |
| 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 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 154 | forcedelete foo.db |
larrybr | 6b7e47f | 2021-09-19 18:31:55 +0000 | [diff] [blame] | 155 | catchcmdex "foo.db" {.echo ON |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 156 | .headers 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; |
| 164 | } |
| 165 | } {0 {.headers ON |
| 166 | CREATE TABLE foo1(a); |
| 167 | INSERT INTO foo1(a) VALUES(1); |
| 168 | CREATE TABLE foo2(b); |
| 169 | INSERT INTO foo2(b) VALUES(1); |
larrybr | f487481 | 2022-05-11 19:59:31 +0000 | [diff] [blame] | 170 | SELECT * FROM foo1; SELECT * FROM foo2; |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 171 | a |
| 172 | 1 |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 173 | b |
| 174 | 1 |
larrybr | f487481 | 2022-05-11 19:59:31 +0000 | [diff] [blame] | 175 | INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2); |
| 176 | SELECT * FROM foo1; SELECT * FROM foo2; |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 177 | a |
| 178 | 1 |
| 179 | 2 |
shaneh | b7977c5 | 2010-01-18 18:17:10 +0000 | [diff] [blame] | 180 | b |
| 181 | 1 |
drh | 849a9d9 | 2013-12-21 15:46:06 +0000 | [diff] [blame] | 182 | 2 |
| 183 | }} |
drh | 74bec6b | 2010-07-19 15:01:43 +0000 | [diff] [blame] | 184 | |
larrybr | c6e2f2e | 2022-03-15 17:57:42 +0000 | [diff] [blame] | 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:" { |
| 189 | SELECT 'unclosed;} |
| 190 | } {1 {Parse error near line 2: unrecognized token: "'unclosed;" |
| 191 | SELECT 'unclosed; |
| 192 | ^--- error here}} |
| 193 | |
larrybr | 8af6d71 | 2022-12-04 23:20:38 +0000 | [diff] [blame] | 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}} |
| 204 | |
larrybr | e8f114b | 2023-01-16 21:49:37 +0000 | [diff] [blame] | 205 | # Verify that .clone handles sequence table. |
| 206 | # See https://sqlite.org/forum/forumpost/71ff9e6c4c |
| 207 | do_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 |
| 216 | done |
| 217 | 2}} |
| 218 | |
larrybr | 8af6d71 | 2022-12-04 23:20:38 +0000 | [diff] [blame] | 219 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 220 | finish_test |