xref: /sqlite-3.40.0/test/shell3.test (revision 2f5f6740)
18df9185cSdrh# 2009 Dec 16
28df9185cSdrh#
38df9185cSdrh# The author disclaims copyright to this source code.  In place of
48df9185cSdrh# a legal notice, here is a blessing:
58df9185cSdrh#
68df9185cSdrh#    May you do good and not evil.
78df9185cSdrh#    May you find forgiveness for yourself and forgive others.
88df9185cSdrh#    May you share freely, never taking more than you give.
98df9185cSdrh#
108df9185cSdrh#***********************************************************************
118df9185cSdrh#
128df9185cSdrh# The focus of this file is testing the CLI shell tool.
138df9185cSdrh#
148df9185cSdrh# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
158df9185cSdrh#
168df9185cSdrh
178df9185cSdrh# Test plan:
188df9185cSdrh#
198df9185cSdrh#   shell3-1.*: Basic tests for running SQL statments from command line.
208df9185cSdrh#   shell3-2.*: Basic tests for running SQL file from command line.
218d463ce1Slarrybr#   shell3-3.*: Basic tests for processing odd SQL constructs.
228df9185cSdrh#
238df9185cSdrhset testdir [file dirname $argv0]
248df9185cSdrhsource $testdir/tester.tcl
25*2f5f6740Slarrybrset CLI [test_cli_invocation]
268df9185cSdrhdb close
278df9185cSdrhforcedelete test.db test.db-journal test.db-wal
288df9185cSdrhsqlite3 db test.db
298df9185cSdrh
308d463ce1Slarrybr
3160c4249fSdrh# There are inconsistencies in command-line argument quoting on Windows.
3260c4249fSdrh# In particular, individual applications are responsible for command-line
3360c4249fSdrh# parsing in Windows, not the shell.  Depending on whether the sqlite3.exe
3460c4249fSdrh# program is compiled with MinGW or MSVC, the command-line parsing is
3560c4249fSdrh# different.  This causes problems for the tests below.  To avoid
3660c4249fSdrh# issues, these tests are disabled for windows.
3760c4249fSdrh#
3860c4249fSdrhif {$::tcl_platform(platform)=="windows"} {
394f69540bSdrh  finish_test
404f69540bSdrh  return
414f69540bSdrh}
424f69540bSdrh
438df9185cSdrh#----------------------------------------------------------------------------
448df9185cSdrh#   shell3-1.*: Basic tests for running SQL statments from command line.
458df9185cSdrh#
468df9185cSdrh
478df9185cSdrh# Run SQL statement from command line
488df9185cSdrhdo_test shell3-1.1 {
499ac99313Smistachkin  forcedelete foo.db
508df9185cSdrh  set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
518df9185cSdrh  set fexist [file exist foo.db]
528df9185cSdrh  list $rc $fexist
538df9185cSdrh} {{0 {}} 1}
548df9185cSdrhdo_test shell3-1.2 {
558df9185cSdrh  catchcmd "foo.db" ".tables"
568df9185cSdrh} {0 t1}
578df9185cSdrhdo_test shell3-1.3 {
588df9185cSdrh  catchcmd "foo.db \"DROP TABLE t1;\""
598df9185cSdrh} {0 {}}
608df9185cSdrhdo_test shell3-1.4 {
618df9185cSdrh  catchcmd "foo.db" ".tables"
628df9185cSdrh} {0 {}}
638df9185cSdrhdo_test shell3-1.5 {
648df9185cSdrh  catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
658df9185cSdrh} {0 {}}
668df9185cSdrhdo_test shell3-1.6 {
678df9185cSdrh  catchcmd "foo.db" ".tables"
688df9185cSdrh} {0 {}}
698df9185cSdrhdo_test shell3-1.7 {
708df9185cSdrh  catchcmd "foo.db \"CREATE TABLE\""
71633c7982Sdrh} {1 {Error: in prepare, incomplete input}}
728df9185cSdrh
738df9185cSdrh#----------------------------------------------------------------------------
748df9185cSdrh#   shell3-2.*: Basic tests for running SQL file from command line.
758df9185cSdrh#
768df9185cSdrh
778df9185cSdrh# Run SQL file from command line
788df9185cSdrhdo_test shell3-2.1 {
799ac99313Smistachkin  forcedelete foo.db
808df9185cSdrh  set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
818df9185cSdrh  set fexist [file exist foo.db]
828df9185cSdrh  list $rc $fexist
838df9185cSdrh} {{0 {}} 1}
848df9185cSdrhdo_test shell3-2.2 {
858df9185cSdrh  catchcmd "foo.db" ".tables"
868df9185cSdrh} {0 t1}
878df9185cSdrhdo_test shell3-2.3 {
888df9185cSdrh  catchcmd "foo.db" "DROP TABLE t1;"
898df9185cSdrh} {0 {}}
908df9185cSdrhdo_test shell3-2.4 {
918df9185cSdrh  catchcmd "foo.db" ".tables"
928df9185cSdrh} {0 {}}
938df9185cSdrhdo_test shell3-2.5 {
948df9185cSdrh  catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
958df9185cSdrh} {0 {}}
968df9185cSdrhdo_test shell3-2.6 {
978df9185cSdrh  catchcmd "foo.db" ".tables"
988df9185cSdrh} {0 {}}
998df9185cSdrhdo_test shell3-2.7 {
1008df9185cSdrh  catchcmd "foo.db" "CREATE TABLE"
101633c7982Sdrh} {1 {Parse error near line 1: incomplete input}}
1028df9185cSdrh
1038d463ce1Slarrybr
1048d463ce1Slarrybr#----------------------------------------------------------------------------
1058d463ce1Slarrybr#   shell3-3.*: Basic tests for processing odd SQL constructs.
1068d463ce1Slarrybr#
1078d463ce1Slarrybr
1088d463ce1Slarrybr# Run combinations of odd identifiers, comments, semicolon placement
1098d463ce1Slarrybrdo_test shell3-3.1 {
1108d463ce1Slarrybr  forcedelete foo.db
1118d463ce1Slarrybr  set rc [ catchcmd "foo.db" {CREATE TABLE t1("
1128d463ce1Slarrybra--.
1138d463ce1Slarrybr" --x
1148d463ce1Slarrybr); CREATE TABLE t2("a[""b""]");
1158d463ce1Slarrybr.header on
1168d463ce1SlarrybrINSERT INTO t1 VALUES ('
1178d463ce1Slarrybrx''y');
1188d463ce1SlarrybrINSERT INTO t2 VALUES ('
1198d463ce1Slarrybr/*.
1208d463ce1Slarrybr.*/ x
1218d463ce1Slarrybr''y');
1228d463ce1SlarrybrSELECT * from t1 limit 1;
1238d463ce1SlarrybrSELECT * from t2 limit 1;
1248d463ce1Slarrybr} ]
1258d463ce1Slarrybr  set fexist [file exist foo.db]
1268d463ce1Slarrybr  list $rc $fexist
1278d463ce1Slarrybr} {{0 {
1288d463ce1Slarrybra--.
1298d463ce1Slarrybr
1308d463ce1Slarrybr
1318d463ce1Slarrybrx'y
1328d463ce1Slarrybra["b"]
1338d463ce1Slarrybr
1348d463ce1Slarrybr/*.
1358d463ce1Slarrybr.*/ x
1368d463ce1Slarrybr'y}} 1}
1378d463ce1Slarrybr
1388df9185cSdrhfinish_test
139