mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-11-23 13:16:16 +00:00
9ed72eb5ae
This merges the version-3.45.1 tag from upstream SQLite git repository to libSQL with the following conflicts resolved: Conflicts: README.md ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java libsql-sqlite3/configure libsql-sqlite3/doc/jsonb.md libsql-sqlite3/ext/fts5/test/fts5faultH.test libsql-sqlite3/ext/fts5/test/fts5origintext.test libsql-sqlite3/ext/fts5/test/fts5origintext2.test libsql-sqlite3/ext/fts5/test/fts5origintext3.test libsql-sqlite3/ext/fts5/test/fts5origintext4.test libsql-sqlite3/ext/fts5/test/fts5origintext5.test libsql-sqlite3/ext/fts5/test/fts5secure8.test libsql-sqlite3/ext/fts5/test/fts5tokenizer2.test libsql-sqlite3/ext/fts5/test/fts5trigram2.test libsql-sqlite3/ext/jni/src/org/sqlite/jni/annotation/Experimental.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqlLogCallback.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/wrapper1/WindowFunction.java libsql-sqlite3/ext/wasm/GNUmakefile libsql-sqlite3/ext/wasm/batch-runner-sahpool.html libsql-sqlite3/ext/wasm/batch-runner-sahpool.js libsql-sqlite3/src/pager.c libsql-sqlite3/src/shell.c.in libsql-sqlite3/src/sqliteInt.h libsql-sqlite3/src/wal.c libsql-sqlite3/test/fts3integrity.test libsql-sqlite3/test/json/jsonb-q1.txt libsql-sqlite3/test/json106.test libsql-sqlite3/test/json107.test libsql-sqlite3/test/jsonb01.test libsql-sqlite3/test/mmapcorrupt.test libsql-sqlite3/test/releasetest_data.tcl libsql-sqlite3/test/shell9.test libsql-sqlite3/test/wapp.tcl libsql-sqlite3/test/wapptest.tcl
149 lines
3.9 KiB
Plaintext
149 lines
3.9 KiB
Plaintext
# 2024 Jan 8
|
|
#
|
|
# 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.
|
|
#
|
|
# And, that it can process a ".dump" script that contains strings
|
|
# delimited using double-quotes in the schema (DQS_DDL setting).
|
|
#
|
|
|
|
# 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
|
|
|
|
#-------------------------------------------------------------------------
|
|
reset_db
|
|
sqlite3_db_config db DQS_DDL 1
|
|
do_execsql_test 3.1.0 {
|
|
CREATE TABLE t4(hello, check( hello IS NOT "xyz") );
|
|
}
|
|
db close
|
|
|
|
# Create .dump file in "testdump.txt".
|
|
#
|
|
set out [open testdump.txt w]
|
|
puts $out [lindex [catchcmd test.db .dump] 1]
|
|
close $out
|
|
do_test 3.1.1 {
|
|
forcedelete test.db
|
|
catchcmd test.db ".read testdump.txt"
|
|
} {0 {}}
|
|
|
|
finish_test
|