shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 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. |
larrybr | 8d463ce | 2021-09-11 02:42:04 +0000 | [diff] [blame] | 21 | # shell3-3.*: Basic tests for processing odd SQL constructs. |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 22 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 23 | set testdir [file dirname $argv0] |
| 24 | source $testdir/tester.tcl |
larrybr | 2f5f674 | 2022-05-09 12:29:47 +0000 | [diff] [blame] | 25 | set CLI [test_cli_invocation] |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 26 | db close |
| 27 | forcedelete test.db test.db-journal test.db-wal |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 28 | sqlite3 db test.db |
| 29 | |
larrybr | 8d463ce | 2021-09-11 02:42:04 +0000 | [diff] [blame] | 30 | |
drh | 60c4249 | 2016-03-26 15:36:36 +0000 | [diff] [blame] | 31 | # 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 | # |
| 38 | if {$::tcl_platform(platform)=="windows"} { |
drh | 4f69540 | 2016-03-25 20:10:20 +0000 | [diff] [blame] | 39 | finish_test |
| 40 | return |
| 41 | } |
| 42 | |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 43 | #---------------------------------------------------------------------------- |
| 44 | # shell3-1.*: Basic tests for running SQL statments from command line. |
| 45 | # |
| 46 | |
| 47 | # Run SQL statement from command line |
| 48 | do_test shell3-1.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 49 | forcedelete foo.db |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 50 | set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] |
| 51 | set fexist [file exist foo.db] |
| 52 | list $rc $fexist |
| 53 | } {{0 {}} 1} |
| 54 | do_test shell3-1.2 { |
| 55 | catchcmd "foo.db" ".tables" |
| 56 | } {0 t1} |
| 57 | do_test shell3-1.3 { |
| 58 | catchcmd "foo.db \"DROP TABLE t1;\"" |
| 59 | } {0 {}} |
| 60 | do_test shell3-1.4 { |
| 61 | catchcmd "foo.db" ".tables" |
| 62 | } {0 {}} |
| 63 | do_test shell3-1.5 { |
| 64 | catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" |
| 65 | } {0 {}} |
| 66 | do_test shell3-1.6 { |
| 67 | catchcmd "foo.db" ".tables" |
| 68 | } {0 {}} |
| 69 | do_test shell3-1.7 { |
| 70 | catchcmd "foo.db \"CREATE TABLE\"" |
drh | 633c798 | 2022-02-08 12:13:16 +0000 | [diff] [blame] | 71 | } {1 {Error: in prepare, incomplete input}} |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 72 | |
| 73 | #---------------------------------------------------------------------------- |
| 74 | # shell3-2.*: Basic tests for running SQL file from command line. |
| 75 | # |
| 76 | |
| 77 | # Run SQL file from command line |
| 78 | do_test shell3-2.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 79 | forcedelete foo.db |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 80 | set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] |
| 81 | set fexist [file exist foo.db] |
| 82 | list $rc $fexist |
| 83 | } {{0 {}} 1} |
| 84 | do_test shell3-2.2 { |
| 85 | catchcmd "foo.db" ".tables" |
| 86 | } {0 t1} |
| 87 | do_test shell3-2.3 { |
| 88 | catchcmd "foo.db" "DROP TABLE t1;" |
| 89 | } {0 {}} |
| 90 | do_test shell3-2.4 { |
| 91 | catchcmd "foo.db" ".tables" |
| 92 | } {0 {}} |
| 93 | do_test shell3-2.5 { |
| 94 | catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" |
| 95 | } {0 {}} |
| 96 | do_test shell3-2.6 { |
| 97 | catchcmd "foo.db" ".tables" |
| 98 | } {0 {}} |
| 99 | do_test shell3-2.7 { |
| 100 | catchcmd "foo.db" "CREATE TABLE" |
drh | 633c798 | 2022-02-08 12:13:16 +0000 | [diff] [blame] | 101 | } {1 {Parse error near line 1: incomplete input}} |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 102 | |
larrybr | 8d463ce | 2021-09-11 02:42:04 +0000 | [diff] [blame] | 103 | |
| 104 | #---------------------------------------------------------------------------- |
| 105 | # shell3-3.*: Basic tests for processing odd SQL constructs. |
| 106 | # |
| 107 | |
| 108 | # Run combinations of odd identifiers, comments, semicolon placement |
| 109 | do_test shell3-3.1 { |
| 110 | forcedelete foo.db |
| 111 | set rc [ catchcmd "foo.db" {CREATE TABLE t1(" |
| 112 | a--. |
| 113 | " --x |
| 114 | ); CREATE TABLE t2("a[""b""]"); |
| 115 | .header on |
| 116 | INSERT INTO t1 VALUES (' |
| 117 | x''y'); |
| 118 | INSERT INTO t2 VALUES (' |
| 119 | /*. |
| 120 | .*/ x |
| 121 | ''y'); |
| 122 | SELECT * from t1 limit 1; |
| 123 | SELECT * from t2 limit 1; |
| 124 | } ] |
| 125 | set fexist [file exist foo.db] |
| 126 | list $rc $fexist |
| 127 | } {{0 { |
| 128 | a--. |
| 129 | |
| 130 | |
| 131 | x'y |
| 132 | a["b"] |
| 133 | |
| 134 | /*. |
| 135 | .*/ x |
| 136 | 'y}} 1} |
| 137 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 138 | finish_test |