mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Automatically turn off DEFENSIVE mode in the shell tool when executing scripts generated by the ".dump" command against an empty database. Add a warning to the top of generated ".dump" scripts that populate virtual tables.
FossilOrigin-Name: 6e9e96b7e7afb9420110f4b93d10b945c9eadfde5e9c81e59ae9ee8167e75707
This commit is contained in:
127
test/shell9.test
Normal file
127
test/shell9.test
Normal file
@ -0,0 +1,127 @@
|
||||
# 2009 Nov 11
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# The focus of this file is testing the CLI shell tool. Specifically,
|
||||
# testing that it is possible to run a ".dump" script that creates
|
||||
# virtual tables without explicitly disabling defensive mode.
|
||||
#
|
||||
|
||||
# Test plan:
|
||||
#
|
||||
# shell1-1.*: Basic command line option handling.
|
||||
# shell1-2.*: Basic "dot" command token parsing.
|
||||
# shell1-3.*: Basic test that "dot" command can be called.
|
||||
# shell1-{4-8}.*: Test various "dot" commands's functionality.
|
||||
# shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
|
||||
#
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set CLI [test_cli_invocation]
|
||||
|
||||
set ::testprefix shell9
|
||||
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test cases shell9-1.* verify that scripts output by .dump may be parsed
|
||||
# by the shell tool without explicitly disabling DEFENSIVE mode, unless
|
||||
# the shell is in safe mode.
|
||||
#
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
|
||||
INSERT INTO t1 VALUES('one', 'two', 'three');
|
||||
}
|
||||
db close
|
||||
|
||||
# Create .dump file in "testdump.txt".
|
||||
#
|
||||
set out [open testdump.txt w]
|
||||
puts $out [lindex [catchcmd test.db .dump] 1]
|
||||
close $out
|
||||
|
||||
# Check testdump.txt can be processed if the initial db is empty.
|
||||
#
|
||||
do_test 1.1.1 {
|
||||
forcedelete test.db
|
||||
catchcmd test.db ".read testdump.txt"
|
||||
} {0 {}}
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 1.1.2 {
|
||||
SELECT * FROM t1;
|
||||
} {one two three}
|
||||
|
||||
# Check testdump.txt cannot be processed if the initial db is not empty.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 1.2.1 {
|
||||
CREATE TABLE t4(hello);
|
||||
}
|
||||
db close
|
||||
do_test 1.2.2 {
|
||||
catchcmd test.db ".read testdump.txt"
|
||||
} {1 {Parse error near line 5: table sqlite_master may not be modified}}
|
||||
|
||||
# Check testdump.txt cannot be processed if the db is in safe mode
|
||||
#
|
||||
do_test 1.3.1 {
|
||||
forcedelete test.db
|
||||
catchsafecmd test.db ".read testdump.txt"
|
||||
} {1 {line 1: cannot run .read in safe mode}}
|
||||
do_test 1.3.2 {
|
||||
set fd [open testdump.txt]
|
||||
set script [read $fd]
|
||||
close $fd
|
||||
forcedelete test.db
|
||||
catchsafecmd test.db $script
|
||||
} {1 {Parse error near line 5: table sqlite_master may not be modified}}
|
||||
do_test 1.3.3 {
|
||||
# Quick check that the above would have worked but for safe mode.
|
||||
forcedelete test.db
|
||||
catchcmd test.db $script
|
||||
} {0 {}}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test cases shell9-2.* verify that a warning is printed at the top of
|
||||
# .dump scripts that contain virtual tables.
|
||||
#
|
||||
proc contains_warning {text} {
|
||||
return [string match "*WARNING: Script requires that*" $text]
|
||||
}
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0.1 {
|
||||
CREATE TABLE t1(x);
|
||||
CREATE TABLE t2(y);
|
||||
INSERT INTO t1 VALUES('one');
|
||||
INSERT INTO t2 VALUES('two');
|
||||
}
|
||||
do_test 2.0.2 {
|
||||
contains_warning [catchcmd test.db .dump]
|
||||
} 0
|
||||
|
||||
do_execsql_test 2.1.1 {
|
||||
CREATE virtual TABLE r1 USING fts5(x);
|
||||
}
|
||||
do_test 2.1.2 {
|
||||
contains_warning [catchcmd test.db .dump]
|
||||
} 1
|
||||
|
||||
do_test 2.2.1 {
|
||||
contains_warning [catchcmd test.db ".dump t1"]
|
||||
} 0
|
||||
do_test 2.2.2 {
|
||||
contains_warning [catchcmd test.db ".dump r1"]
|
||||
} 1
|
||||
|
||||
finish_test
|
Reference in New Issue
Block a user