AryaWu/sqlite
0
1# 2009 Dec 162#3# The author disclaims copyright to this source code. In place of4# 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: shell12#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.tcl26set CLI [test_cli_invocation]27db close28forcedelete test.db test.db-journal test.db-wal29sqlite3 db test.db30 31 32# There are inconsistencies in command-line argument quoting on Windows.33# In particular, individual applications are responsible for command-line34# parsing in Windows, not the shell. Depending on whether the sqlite3.exe35# program is compiled with MinGW or MSVC, the command-line parsing is36# different. This causes problems for the tests below. To avoid37# issues, these tests are disabled for windows.38#39if {$::tcl_platform(platform) eq "windows"} {40 finish_test41 return42}43 44#----------------------------------------------------------------------------45# shell3-1.*: Basic tests for running SQL statments from command line.46#47 48# Run SQL statement from command line49do_test shell3-1.1 {50 forcedelete foo.db51 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]52 set fexist [file exist foo.db]53 list $rc $fexist54} {{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 {Error: in prepare, incomplete input}}73 74#----------------------------------------------------------------------------75# shell3-2.*: Basic tests for running SQL file from command line.76#77 78# Run SQL file from command line79do_test shell3-2.1 {80 forcedelete foo.db81 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]82 set fexist [file exist foo.db]83 list $rc $fexist84} {{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 placement110do_test shell3-3.1 {111 forcedelete foo.db112 set rc [ catchcmd "foo.db" {CREATE TABLE t1("113a--.114" --x115); CREATE TABLE t2("a[""b""]");116.header on117INSERT INTO t1 VALUES ('118x''y');119INSERT INTO t2 VALUES ('120/*.121.*/ x122''y');123SELECT * from t1 limit 1;124SELECT * from t2 limit 1;125} ]126 set fexist [file exist foo.db]127 list $rc $fexist128} {{0 {129a--.130 131 132x'y133a["b"]134 135/*.136.*/ x137'y}} 1}138 139do_test shell3-3.2 {140 catchcmd "" {141.open xyz.db142SELECT ;143 }144} {1 {Parse error near line 3: near ";": syntax error145 SELECT ;146 ^--- error here}}147 148finish_test149 