Optimizations to ParseFinalize() to make up for the extra cleanup associated
[sqlite.git] / test / shell9.test
blob34c9d8c5d6d01ce7d851ec7aab310d5d1acf8c46
1 # 2024 Jan 8
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. Specifically, 
13 # testing that it is possible to run a ".dump" script that creates
14 # virtual tables without explicitly disabling defensive mode.
16 # And, that it can process a ".dump" script that contains strings
17 # delimited using double-quotes in the schema (DQS_DDL setting).
20 # Test plan:
22 #   shell1-1.*: Basic command line option handling.
23 #   shell1-2.*: Basic "dot" command token parsing.
24 #   shell1-3.*: Basic test that "dot" command can be called.
25 #   shell1-{4-8}.*: Test various "dot" commands's functionality.
26 #   shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
28 set testdir [file dirname $argv0]
29 source $testdir/tester.tcl
30 set CLI [test_cli_invocation]
32 set ::testprefix shell9
34 ifcapable !fts5 {
35   finish_test
36   return
39 #----------------------------------------------------------------------------
40 # Test cases shell9-1.* verify that scripts output by .dump may be parsed
41 # by the shell tool without explicitly disabling DEFENSIVE mode, unless
42 # the shell is in safe mode.
44 do_execsql_test 1.0 {
45   CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
46   INSERT INTO t1 VALUES('one', 'two', 'three');
48 db close
50 # Create .dump file in "testdump.txt".
52 set out [open testdump.txt w]
53 puts $out [lindex [catchcmd test.db .dump] 1]
54 close $out
56 # Check testdump.txt can be processed if the initial db is empty.
58 do_test 1.1.1 {
59   forcedelete test.db
60   catchcmd test.db ".read testdump.txt"
61 } {0 {}}
62 sqlite3 db test.db
63 do_execsql_test 1.1.2 {
64   SELECT * FROM t1;
65 } {one two three}
67 # Check testdump.txt cannot be processed if the initial db is not empty.
69 reset_db
70 do_execsql_test 1.2.1 {
71   CREATE TABLE t4(hello);
73 db close
74 do_test 1.2.2 {
75   catchcmd test.db ".read testdump.txt"
76 } {1 {Parse error near line 5: table sqlite_master may not be modified}}
78 # Check testdump.txt cannot be processed if the db is in safe mode
80 do_test 1.3.1 {
81   forcedelete test.db
82   catchsafecmd test.db ".read testdump.txt"
83 } {1 {line 1: cannot run .read in safe mode}}
84 do_test 1.3.2 {
85   set fd [open testdump.txt]
86   set script [read $fd]
87   close $fd
88   forcedelete test.db
89   catchsafecmd test.db $script
90 } {1 {Parse error near line 5: table sqlite_master may not be modified}}
91 do_test 1.3.3 {
92   # Quick check that the above would have worked but for safe mode.
93   forcedelete test.db
94   catchcmd test.db $script
95 } {0 {}}
97 #----------------------------------------------------------------------------
98 # Test cases shell9-2.* verify that a warning is printed at the top of
99 # .dump scripts that contain virtual tables.
101 proc contains_warning {text} {
102   return [string match "*WARNING: Script requires that*" $text]
105 reset_db
106 do_execsql_test 2.0.1 {
107   CREATE TABLE t1(x);
108   CREATE TABLE t2(y);
109   INSERT INTO t1 VALUES('one');
110   INSERT INTO t2 VALUES('two');
112 do_test 2.0.2 {
113   contains_warning [catchcmd test.db .dump]
114 } 0
116 do_execsql_test 2.1.1 {
117   CREATE virtual TABLE r1 USING fts5(x);
119 do_test 2.1.2 {
120   contains_warning [catchcmd test.db .dump]
121 } 1
123 do_test 2.2.1 {
124   contains_warning [catchcmd test.db ".dump t1"]
125 } 0
126 do_test 2.2.2 {
127   contains_warning [catchcmd test.db ".dump r1"]
128 } 1
130 #-------------------------------------------------------------------------
131 reset_db
132 sqlite3_db_config db DQS_DDL 1
133 do_execsql_test 3.1.0 {
134   CREATE TABLE t4(hello, check( hello IS NOT "xyz") );
136 db close
138 # Create .dump file in "testdump.txt".
140 set out [open testdump.txt w]
141 puts $out [lindex [catchcmd test.db .dump] 1]
142 close $out
143 do_test 3.1.1 {
144   forcedelete test.db
145   catchcmd test.db ".read testdump.txt"
146 } {0 {}}
148 finish_test