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# 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. 21# 22set testdir [file dirname $argv0] 23source $testdir/tester.tcl 24if {$tcl_platform(platform)=="windows"} { 25 set CLI "sqlite3.exe" 26} else { 27 set CLI "./sqlite3" 28} 29if {![file executable $CLI]} { 30 finish_test 31 return 32} 33db close 34forcedelete test.db test.db-journal test.db-wal 35sqlite3 db test.db 36 37#---------------------------------------------------------------------------- 38# shell3-1.*: Basic tests for running SQL statments from command line. 39# 40 41# Run SQL statement from command line 42do_test shell3-1.1 { 43 file delete -force foo.db 44 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] 45 set fexist [file exist foo.db] 46 list $rc $fexist 47} {{0 {}} 1} 48do_test shell3-1.2 { 49 catchcmd "foo.db" ".tables" 50} {0 t1} 51do_test shell3-1.3 { 52 catchcmd "foo.db \"DROP TABLE t1;\"" 53} {0 {}} 54do_test shell3-1.4 { 55 catchcmd "foo.db" ".tables" 56} {0 {}} 57do_test shell3-1.5 { 58 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" 59} {0 {}} 60do_test shell3-1.6 { 61 catchcmd "foo.db" ".tables" 62} {0 {}} 63do_test shell3-1.7 { 64 catchcmd "foo.db \"CREATE TABLE\"" 65} {1 {Error: near "TABLE": syntax error}} 66 67#---------------------------------------------------------------------------- 68# shell3-2.*: Basic tests for running SQL file from command line. 69# 70 71# Run SQL file from command line 72do_test shell3-2.1 { 73 file delete -force foo.db 74 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] 75 set fexist [file exist foo.db] 76 list $rc $fexist 77} {{0 {}} 1} 78do_test shell3-2.2 { 79 catchcmd "foo.db" ".tables" 80} {0 t1} 81do_test shell3-2.3 { 82 catchcmd "foo.db" "DROP TABLE t1;" 83} {0 {}} 84do_test shell3-2.4 { 85 catchcmd "foo.db" ".tables" 86} {0 {}} 87do_test shell3-2.5 { 88 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" 89} {0 {}} 90do_test shell3-2.6 { 91 catchcmd "foo.db" ".tables" 92} {0 {}} 93do_test shell3-2.7 { 94 catchcmd "foo.db" "CREATE TABLE" 95} {1 {Error: incomplete SQL: CREATE TABLE}} 96 97finish_test 98