blob: f8d69946e7cbdbdd5586acf0911df9d1e6bb759f [file] [log] [blame]
shanehca7dfda2009-12-17 21:07:54 +00001# 2009 Dec 16
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11#
12# The focus of this file is testing the CLI shell tool.
13#
14# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
15#
16
17# Test plan:
18#
19# shell3-1.*: Basic tests for running SQL statments from command line.
20# shell3-2.*: Basic tests for running SQL file from command line.
larrybr8d463ce2021-09-11 02:42:04 +000021# shell3-3.*: Basic tests for processing odd SQL constructs.
shanehca7dfda2009-12-17 21:07:54 +000022#
drh8df91852012-04-24 12:46:05 +000023set testdir [file dirname $argv0]
24source $testdir/tester.tcl
larrybr2f5f6742022-05-09 12:29:47 +000025set CLI [test_cli_invocation]
drh8df91852012-04-24 12:46:05 +000026db close
27forcedelete test.db test.db-journal test.db-wal
shanehca7dfda2009-12-17 21:07:54 +000028sqlite3 db test.db
29
larrybr8d463ce2021-09-11 02:42:04 +000030
drh60c42492016-03-26 15:36:36 +000031# There are inconsistencies in command-line argument quoting on Windows.
32# In particular, individual applications are responsible for command-line
33# parsing in Windows, not the shell. Depending on whether the sqlite3.exe
34# program is compiled with MinGW or MSVC, the command-line parsing is
35# different. This causes problems for the tests below. To avoid
36# issues, these tests are disabled for windows.
37#
38if {$::tcl_platform(platform)=="windows"} {
drh4f695402016-03-25 20:10:20 +000039 finish_test
40 return
41}
42
shanehca7dfda2009-12-17 21:07:54 +000043#----------------------------------------------------------------------------
44# shell3-1.*: Basic tests for running SQL statments from command line.
45#
46
47# Run SQL statement from command line
48do_test shell3-1.1 {
mistachkin9ac99312013-09-13 23:26:47 +000049 forcedelete foo.db
shanehca7dfda2009-12-17 21:07:54 +000050 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
51 set fexist [file exist foo.db]
52 list $rc $fexist
53} {{0 {}} 1}
54do_test shell3-1.2 {
55 catchcmd "foo.db" ".tables"
56} {0 t1}
57do_test shell3-1.3 {
58 catchcmd "foo.db \"DROP TABLE t1;\""
59} {0 {}}
60do_test shell3-1.4 {
61 catchcmd "foo.db" ".tables"
62} {0 {}}
63do_test shell3-1.5 {
64 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
65} {0 {}}
66do_test shell3-1.6 {
67 catchcmd "foo.db" ".tables"
68} {0 {}}
69do_test shell3-1.7 {
70 catchcmd "foo.db \"CREATE TABLE\""
drh633c7982022-02-08 12:13:16 +000071} {1 {Error: in prepare, incomplete input}}
shanehca7dfda2009-12-17 21:07:54 +000072
73#----------------------------------------------------------------------------
74# shell3-2.*: Basic tests for running SQL file from command line.
75#
76
77# Run SQL file from command line
78do_test shell3-2.1 {
mistachkin9ac99312013-09-13 23:26:47 +000079 forcedelete foo.db
shanehca7dfda2009-12-17 21:07:54 +000080 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
81 set fexist [file exist foo.db]
82 list $rc $fexist
83} {{0 {}} 1}
84do_test shell3-2.2 {
85 catchcmd "foo.db" ".tables"
86} {0 t1}
87do_test shell3-2.3 {
88 catchcmd "foo.db" "DROP TABLE t1;"
89} {0 {}}
90do_test shell3-2.4 {
91 catchcmd "foo.db" ".tables"
92} {0 {}}
93do_test shell3-2.5 {
94 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
95} {0 {}}
96do_test shell3-2.6 {
97 catchcmd "foo.db" ".tables"
98} {0 {}}
99do_test shell3-2.7 {
100 catchcmd "foo.db" "CREATE TABLE"
drh633c7982022-02-08 12:13:16 +0000101} {1 {Parse error near line 1: incomplete input}}
shanehca7dfda2009-12-17 21:07:54 +0000102
larrybr8d463ce2021-09-11 02:42:04 +0000103
104#----------------------------------------------------------------------------
105# shell3-3.*: Basic tests for processing odd SQL constructs.
106#
107
108# Run combinations of odd identifiers, comments, semicolon placement
109do_test shell3-3.1 {
110 forcedelete foo.db
111 set rc [ catchcmd "foo.db" {CREATE TABLE t1("
112a--.
113" --x
114); CREATE TABLE t2("a[""b""]");
115.header on
116INSERT INTO t1 VALUES ('
117x''y');
118INSERT INTO t2 VALUES ('
119/*.
120.*/ x
121''y');
122SELECT * from t1 limit 1;
123SELECT * from t2 limit 1;
124} ]
125 set fexist [file exist foo.db]
126 list $rc $fexist
127} {{0 {
128a--.
129
130
131x'y
132a["b"]
133
134/*.
135.*/ x
136'y}} 1}
137
drh8df91852012-04-24 12:46:05 +0000138finish_test