interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / shell3.test

148 lines · 3723 bytes Raw Blame History
1# 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# TESTRUNNER: shell
12#
13# The focus of this file is testing the CLI shell tool.
14#
15# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
16#
17
18# Test plan:
19#
20# shell3-1.*: Basic tests for running SQL statments from command line.
21# shell3-2.*: Basic tests for running SQL file from command line.
22# shell3-3.*: Basic tests for processing odd SQL constructs.
23#
24set testdir [file dirname $argv0]
25source $testdir/tester.tcl
26set CLI [test_cli_invocation]
27db close
28forcedelete test.db test.db-journal test.db-wal
29sqlite3 db test.db
30
31
32# There are inconsistencies in command-line argument quoting on Windows.
33# In particular, individual applications are responsible for command-line
34# parsing in Windows, not the shell. Depending on whether the sqlite3.exe
35# program is compiled with MinGW or MSVC, the command-line parsing is
36# different. This causes problems for the tests below. To avoid
37# issues, these tests are disabled for windows.
38#
39if {$::tcl_platform(platform) eq "windows"} {
40 finish_test
41 return
42}
43
44#----------------------------------------------------------------------------
45# shell3-1.*: Basic tests for running SQL statments from command line.
46#
47
48# Run SQL statement from command line
49do_test shell3-1.1 {
50 forcedelete foo.db
51 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
52 set fexist [file exist foo.db]
53 list $rc $fexist
54} {{0 {}} 1}
55do_test shell3-1.2 {
56 catchcmd "foo.db" ".tables"
57} {0 t1}
58do_test shell3-1.3 {
59 catchcmd "foo.db \"DROP TABLE t1;\""
60} {0 {}}
61do_test shell3-1.4 {
62 catchcmd "foo.db" ".tables"
63} {0 {}}
64do_test shell3-1.5 {
65 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
66} {0 {}}
67do_test shell3-1.6 {
68 catchcmd "foo.db" ".tables"
69} {0 {}}
70do_test shell3-1.7 {
71 catchcmd "foo.db \"CREATE TABLE\""
72} {1 {Parse error in 2nd command line argument: incomplete input}}
73
74#----------------------------------------------------------------------------
75# shell3-2.*: Basic tests for running SQL file from command line.
76#
77
78# Run SQL file from command line
79do_test shell3-2.1 {
80 forcedelete foo.db
81 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
82 set fexist [file exist foo.db]
83 list $rc $fexist
84} {{0 {}} 1}
85do_test shell3-2.2 {
86 catchcmd "foo.db" ".tables"
87} {0 t1}
88do_test shell3-2.3 {
89 catchcmd "foo.db" "DROP TABLE t1;"
90} {0 {}}
91do_test shell3-2.4 {
92 catchcmd "foo.db" ".tables"
93} {0 {}}
94do_test shell3-2.5 {
95 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
96} {0 {}}
97do_test shell3-2.6 {
98 catchcmd "foo.db" ".tables"
99} {0 {}}
100do_test shell3-2.7 {
101 catchcmd "foo.db" "CREATE TABLE"
102} {1 {Parse error near line 1: incomplete input}}
103
104
105#----------------------------------------------------------------------------
106# shell3-3.*: Basic tests for processing odd SQL constructs.
107#
108
109# Run combinations of odd identifiers, comments, semicolon placement
110do_test shell3-3.1 {
111 forcedelete foo.db
112 set rc [ catchcmd "foo.db" {CREATE TABLE t1("
113a--.
114" --x
115); CREATE TABLE t2("a[""b""]");
116.header on
117INSERT INTO t1 VALUES ('
118x''y');
119INSERT INTO t2 VALUES ('
120/*.
121.*/ x
122''y');
123SELECT * from t1 limit 1;
124SELECT * from t2 limit 1;
125} ]
126 set fexist [file exist foo.db]
127 list $rc $fexist
128} {{0 {
129a--.
130
131
132x'y
133a["b"]
134
135/*.
136.*/ x
137'y}} 1}
138
139do_test shell3-3.2 {
140 catchcmd "" {
141.open xyz.db
142SELECT ;
143 }
144} {1 {Parse error near line 3: near ";": syntax error
145 SELECT ;
146 ^--- error here}}
147
148finish_test