2009-12-18 00:07:54 +03:00
|
|
|
# 2009 Dec 16
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
|
|
|
# shell3-1.*: Basic tests for running SQL statments from command line.
|
|
|
|
# shell3-2.*: Basic tests for running SQL file from command line.
|
2021-09-11 05:42:04 +03:00
|
|
|
# shell3-3.*: Basic tests for processing odd SQL constructs.
|
2009-12-18 00:07:54 +03:00
|
|
|
#
|
2012-04-24 16:46:05 +04:00
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2016-03-15 12:55:44 +03:00
|
|
|
set CLI [test_find_cli]
|
2012-04-24 16:46:05 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db test.db-journal test.db-wal
|
2009-12-18 00:07:54 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
2021-09-11 05:42:04 +03:00
|
|
|
|
2016-03-26 18:36:36 +03:00
|
|
|
# There are inconsistencies in command-line argument quoting on Windows.
|
|
|
|
# In particular, individual applications are responsible for command-line
|
|
|
|
# parsing in Windows, not the shell. Depending on whether the sqlite3.exe
|
|
|
|
# program is compiled with MinGW or MSVC, the command-line parsing is
|
|
|
|
# different. This causes problems for the tests below. To avoid
|
|
|
|
# issues, these tests are disabled for windows.
|
|
|
|
#
|
|
|
|
if {$::tcl_platform(platform)=="windows"} {
|
2016-03-25 23:10:20 +03:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2009-12-18 00:07:54 +03:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# shell3-1.*: Basic tests for running SQL statments from command line.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Run SQL statement from command line
|
|
|
|
do_test shell3-1.1 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2009-12-18 00:07:54 +03:00
|
|
|
set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
|
|
|
|
set fexist [file exist foo.db]
|
|
|
|
list $rc $fexist
|
|
|
|
} {{0 {}} 1}
|
|
|
|
do_test shell3-1.2 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 t1}
|
|
|
|
do_test shell3-1.3 {
|
|
|
|
catchcmd "foo.db \"DROP TABLE t1;\""
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-1.4 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-1.5 {
|
|
|
|
catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-1.6 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-1.7 {
|
|
|
|
catchcmd "foo.db \"CREATE TABLE\""
|
2021-10-26 19:57:09 +03:00
|
|
|
} {1 {Error: in prepare, incomplete input (1)}}
|
2009-12-18 00:07:54 +03:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# shell3-2.*: Basic tests for running SQL file from command line.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Run SQL file from command line
|
|
|
|
do_test shell3-2.1 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2009-12-18 00:07:54 +03:00
|
|
|
set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
|
|
|
|
set fexist [file exist foo.db]
|
|
|
|
list $rc $fexist
|
|
|
|
} {{0 {}} 1}
|
|
|
|
do_test shell3-2.2 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 t1}
|
|
|
|
do_test shell3-2.3 {
|
|
|
|
catchcmd "foo.db" "DROP TABLE t1;"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-2.4 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-2.5 {
|
|
|
|
catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-2.6 {
|
|
|
|
catchcmd "foo.db" ".tables"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell3-2.7 {
|
|
|
|
catchcmd "foo.db" "CREATE TABLE"
|
2022-02-08 14:52:45 +03:00
|
|
|
} {1 {Parse error near line 1: incomplete input (1)}}
|
2009-12-18 00:07:54 +03:00
|
|
|
|
2021-09-11 05:42:04 +03:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# shell3-3.*: Basic tests for processing odd SQL constructs.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Run combinations of odd identifiers, comments, semicolon placement
|
|
|
|
do_test shell3-3.1 {
|
|
|
|
forcedelete foo.db
|
|
|
|
set rc [ catchcmd "foo.db" {CREATE TABLE t1("
|
|
|
|
a--.
|
|
|
|
" --x
|
|
|
|
); CREATE TABLE t2("a[""b""]");
|
|
|
|
.header on
|
|
|
|
INSERT INTO t1 VALUES ('
|
|
|
|
x''y');
|
|
|
|
INSERT INTO t2 VALUES ('
|
|
|
|
/*.
|
|
|
|
.*/ x
|
|
|
|
''y');
|
|
|
|
SELECT * from t1 limit 1;
|
|
|
|
SELECT * from t2 limit 1;
|
|
|
|
} ]
|
|
|
|
set fexist [file exist foo.db]
|
|
|
|
list $rc $fexist
|
|
|
|
} {{0 {
|
|
|
|
a--.
|
|
|
|
|
|
|
|
|
|
|
|
x'y
|
|
|
|
a["b"]
|
|
|
|
|
|
|
|
/*.
|
|
|
|
.*/ x
|
|
|
|
'y}} 1}
|
|
|
|
|
2012-04-24 16:46:05 +04:00
|
|
|
finish_test
|