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).
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
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.
45 CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
46 INSERT INTO t1 VALUES('one', 'two', 'three');
50 # Create .dump file in "testdump.txt".
52 set out [open testdump.txt w]
53 puts $out [lindex [catchcmd test.db .dump] 1]
56 # Check testdump.txt can be processed if the initial db is empty.
60 catchcmd test.db ".read testdump.txt"
63 do_execsql_test 1.1.2 {
67 # Check testdump.txt cannot be processed if the initial db is not empty.
70 do_execsql_test 1.2.1 {
71 CREATE TABLE t4(hello);
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
82 catchsafecmd test.db ".read testdump.txt"
83 } {1 {line 1: cannot run .read in safe mode}}
85 set fd [open testdump.txt]
89 catchsafecmd test.db $script
90 } {1 {Parse error near line 5: table sqlite_master may not be modified}}
92 # Quick check that the above would have worked but for safe mode.
94 catchcmd test.db $script
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]
106 do_execsql_test 2.0.1 {
109 INSERT INTO t1 VALUES('one');
110 INSERT INTO t2 VALUES('two');
113 contains_warning [catchcmd test.db .dump]
116 do_execsql_test 2.1.1 {
117 CREATE virtual TABLE r1 USING fts5(x);
120 contains_warning [catchcmd test.db .dump]
124 contains_warning [catchcmd test.db ".dump t1"]
127 contains_warning [catchcmd test.db ".dump r1"]
130 #-------------------------------------------------------------------------
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") );
138 # Create .dump file in "testdump.txt".
140 set out [open testdump.txt w]
141 puts $out [lindex [catchcmd test.db .dump] 1]
145 catchcmd test.db ".read testdump.txt"