Index: third_party/sqlite/src/test/shell1.test |
diff --git a/third_party/sqlite/src/test/shell1.test b/third_party/sqlite/src/test/shell1.test |
index ab382e74cbe052807a24606e67291781e2a36f97..2fda62ee13f1ba53f605c06b020c25c15b951d21 100644 |
--- a/third_party/sqlite/src/test/shell1.test |
+++ b/third_party/sqlite/src/test/shell1.test |
@@ -45,20 +45,21 @@ do_test shell1-1.1.1 { |
list $rc \ |
[regexp {Error: unknown option: -bad} $res] |
} {1 1} |
-# error on extra options |
-do_test shell1-1.1.2 { |
- set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""] |
+do_test shell1-1.1.1b { |
+ set res [catchcmd "test.db -bad" ""] |
set rc [lindex $res 0] |
list $rc \ |
- [regexp {Error: too many options: "select 4"} $res] |
+ [regexp {Error: unknown option: -bad} $res] |
} {1 1} |
# error on extra options |
+do_test shell1-1.1.2 { |
+ catchcmd "test.db \"select 3\" \"select 4\"" "" |
+} {0 {3 |
+4}} |
+# error on extra options |
do_test shell1-1.1.3 { |
- set res [catchcmd "-bad FOO test.db BAD" ".quit"] |
- set rc [lindex $res 0] |
- list $rc \ |
- [regexp {Error: too many options: "BAD"} $res] |
-} {1 1} |
+ catchcmd "test.db FOO test.db BAD" ".quit" |
+} {1 {Error: near "FOO": syntax error}} |
# -help |
do_test shell1-1.2.1 { |
@@ -75,11 +76,11 @@ do_test shell1-1.3.1 { |
catchcmd "-init FOO test.db" "" |
} {0 {}} |
do_test shell1-1.3.2 { |
- set res [catchcmd "-init FOO test.db .quit BAD" ""] |
- set rc [lindex $res 0] |
- list $rc \ |
- [regexp {Error: too many options: "BAD"} $res] |
-} {1 1} |
+ catchcmd "-init FOO test.db .quit BAD" "" |
+} {0 {}} |
+do_test shell1-1.3.3 { |
+ catchcmd "-init FOO test.db BAD .quit" "" |
+} {1 {Error: near "BAD": syntax error}} |
# -echo print commands before execution |
do_test shell1-1.4.1 { |
@@ -206,10 +207,10 @@ do_test shell1-2.2.4 { |
} {0 {}} |
do_test shell1-2.2.5 { |
catchcmd "test.db" ".mode \"insert FOO" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-2.2.6 { |
catchcmd "test.db" ".mode \'insert FOO" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
# check multiple tokens, and quoted tokens |
do_test shell1-2.3.1 { |
@@ -237,7 +238,7 @@ do_test shell1-2.3.7 { |
# check quoted args are unquoted |
do_test shell1-2.4.1 { |
catchcmd "test.db" ".mode FOO" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-2.4.2 { |
catchcmd "test.db" ".mode csv" |
} {0 {}} |
@@ -405,35 +406,39 @@ do_test shell1-3.11.3 { |
catchcmd "test.db" ".import FOO BAR BAD" |
} {1 {Usage: .import FILE TABLE}} |
-# .indices ?TABLE? Show names of all indices |
-# If TABLE specified, only show indices for tables |
+# .indexes ?TABLE? Show names of all indexes |
+# If TABLE specified, only show indexes for tables |
# matching LIKE pattern TABLE. |
do_test shell1-3.12.1 { |
- catchcmd "test.db" ".indices" |
+ catchcmd "test.db" ".indexes" |
} {0 {}} |
do_test shell1-3.12.2 { |
+ catchcmd "test.db" ".indexes FOO" |
+} {0 {}} |
+do_test shell1-3.12.2-legacy { |
catchcmd "test.db" ".indices FOO" |
} {0 {}} |
do_test shell1-3.12.3 { |
# too many arguments |
- catchcmd "test.db" ".indices FOO BAD" |
-} {1 {Usage: .indices ?LIKE-PATTERN?}} |
+ catchcmd "test.db" ".indexes FOO BAD" |
+} {1 {Usage: .indexes ?LIKE-PATTERN?}} |
# .mode MODE ?TABLE? Set output mode where MODE is one of: |
+# ascii Columns/rows delimited by 0x1F and 0x1E |
# csv Comma-separated values |
# column Left-aligned columns. (See .width) |
# html HTML <table> code |
# insert SQL insert statements for TABLE |
# line One value per line |
-# list Values delimited by .separator string |
+# list Values delimited by .separator strings |
# tabs Tab-separated values |
# tcl TCL list elements |
do_test shell1-3.13.1 { |
catchcmd "test.db" ".mode" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-3.13.2 { |
catchcmd "test.db" ".mode FOO" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-3.13.3 { |
catchcmd "test.db" ".mode csv" |
} {0 {}} |
@@ -466,10 +471,10 @@ do_test shell1-3.13.11 { |
# don't allow partial mode type matches |
do_test shell1-3.13.12 { |
catchcmd "test.db" ".mode l" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-3.13.13 { |
catchcmd "test.db" ".mode li" |
-} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
+} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
do_test shell1-3.13.14 { |
catchcmd "test.db" ".mode lin" |
} {0 {}} |
@@ -585,10 +590,10 @@ CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
CREATE VIEW v1 AS SELECT y+1 FROM v2;}} |
db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} |
-# .separator STRING Change separator used by output mode and .import |
+# .separator STRING Change column separator used by output and .import |
do_test shell1-3.22.1 { |
catchcmd "test.db" ".separator" |
-} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} |
+} {1 {Usage: .separator COL ?ROW?}} |
do_test shell1-3.22.2 { |
catchcmd "test.db" ".separator FOO" |
} {0 {}} |
@@ -598,7 +603,7 @@ do_test shell1-3.22.3 { |
do_test shell1-3.22.4 { |
# too many arguments |
catchcmd "test.db" ".separator FOO BAD BAD2" |
-} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} |
+} {1 {Usage: .separator COL ?ROW?}} |
# .show Show the current values for various settings |
do_test shell1-3.23.1 { |
@@ -609,10 +614,11 @@ do_test shell1-3.23.1 { |
[regexp {mode:} $res] \ |
[regexp {nullvalue:} $res] \ |
[regexp {output:} $res] \ |
- [regexp {separator:} $res] \ |
+ [regexp {colseparator:} $res] \ |
+ [regexp {rowseparator:} $res] \ |
[regexp {stats:} $res] \ |
[regexp {width:} $res] |
-} {1 1 1 1 1 1 1 1 1} |
+} {1 1 1 1 1 1 1 1 1 1} |
do_test shell1-3.23.2 { |
# too many arguments |
catchcmd "test.db" ".show BAD" |
@@ -732,6 +738,9 @@ do_test shell1-4.1 { |
PRAGMA encoding=UTF16; |
CREATE TABLE t1(x); |
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
+ CREATE TABLE t3(x,y); |
+ INSERT INTO t3 VALUES(1,null), (2,''), (3,1), |
+ (4,2.25), (5,'hello'), (6,x'807f'); |
} |
catchcmd test.db {.dump} |
} {0 {PRAGMA foreign_keys=OFF; |
@@ -743,11 +752,18 @@ INSERT INTO "t1" VALUES(1); |
INSERT INTO "t1" VALUES(2.25); |
INSERT INTO "t1" VALUES('hello'); |
INSERT INTO "t1" VALUES(X'807F'); |
+CREATE TABLE t3(x,y); |
+INSERT INTO "t3" VALUES(1,NULL); |
+INSERT INTO "t3" VALUES(2,''); |
+INSERT INTO "t3" VALUES(3,1); |
+INSERT INTO "t3" VALUES(4,2.25); |
+INSERT INTO "t3" VALUES(5,'hello'); |
+INSERT INTO "t3" VALUES(6,X'807F'); |
COMMIT;}} |
# Test the output of ".mode insert" |
# |
-do_test shell1-4.2 { |
+do_test shell1-4.2.1 { |
catchcmd test.db ".mode insert t1\nselect * from t1;" |
} {0 {INSERT INTO t1 VALUES(NULL); |
INSERT INTO t1 VALUES(''); |
@@ -756,6 +772,39 @@ INSERT INTO t1 VALUES(2.25); |
INSERT INTO t1 VALUES('hello'); |
INSERT INTO t1 VALUES(X'807f');}} |
+# Test the output of ".mode insert" with headers |
+# |
+do_test shell1-4.2.2 { |
+ catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;" |
+} {0 {INSERT INTO t1(x) VALUES(NULL); |
+INSERT INTO t1(x) VALUES(''); |
+INSERT INTO t1(x) VALUES(1); |
+INSERT INTO t1(x) VALUES(2.25); |
+INSERT INTO t1(x) VALUES('hello'); |
+INSERT INTO t1(x) VALUES(X'807f');}} |
+ |
+# Test the output of ".mode insert" |
+# |
+do_test shell1-4.2.3 { |
+ catchcmd test.db ".mode insert t3\nselect * from t3;" |
+} {0 {INSERT INTO t3 VALUES(1,NULL); |
+INSERT INTO t3 VALUES(2,''); |
+INSERT INTO t3 VALUES(3,1); |
+INSERT INTO t3 VALUES(4,2.25); |
+INSERT INTO t3 VALUES(5,'hello'); |
+INSERT INTO t3 VALUES(6,X'807f');}} |
+ |
+# Test the output of ".mode insert" with headers |
+# |
+do_test shell1-4.2.4 { |
+ catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;" |
+} {0 {INSERT INTO t3(x,y) VALUES(1,NULL); |
+INSERT INTO t3(x,y) VALUES(2,''); |
+INSERT INTO t3(x,y) VALUES(3,1); |
+INSERT INTO t3(x,y) VALUES(4,2.25); |
+INSERT INTO t3(x,y) VALUES(5,'hello'); |
+INSERT INTO t3(x,y) VALUES(6,X'807f');}} |
+ |
# Test the output of ".mode tcl" |
# |
do_test shell1-4.3 { |
@@ -812,4 +861,61 @@ do_test shell1-4.6 { |
";" |
"$"} 7} |
+# Test using arbitrary byte data with the shell via standard input/output. |
+# |
+do_test shell1-5.0 { |
+ # |
+ # NOTE: Skip NUL byte because it appears to be incompatible with command |
+ # shell argument parsing. |
+ # |
+ for {set i 1} {$i < 256} {incr i} { |
+ # |
+ # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats |
+ # command channels opened for it as textual ones), the carriage |
+ # return character (and on Windows, the end-of-file character) |
+ # cannot be used here. |
+ # |
+ if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} { |
+ continue |
+ } |
+ set hex [format %02X $i] |
+ set char [subst \\x$hex]; set oldChar $char |
+ set escapes [list] |
+ if {$tcl_platform(platform)=="windows"} { |
+ # |
+ # NOTE: On Windows, we need to escape all the whitespace characters, |
+ # the alarm (\a) character, and those with special meaning to |
+ # the SQLite shell itself. |
+ # |
+ set escapes [list \ |
+ \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \ |
+ " " "\" \"" \" \\\" ' \"'\" \\ \\\\] |
+ } else { |
+ # |
+ # NOTE: On Unix, we need to escape most of the whitespace characters |
+ # and those with special meaning to the SQLite shell itself. |
+ # The alarm (\a), backspace (\b), and carriage-return (\r) |
+ # characters do not appear to require escaping on Unix. For |
+ # the alarm and backspace characters, this is probably due to |
+ # differences in the command shell. For the carriage-return, |
+ # it is probably due to differences in how Tcl handles command |
+ # channel end-of-line translations. |
+ # |
+ set escapes [list \ |
+ \t \\t \n \\n \v \\v \f \\f \ |
+ " " "\" \"" \" \\\" ' \"'\" \\ \\\\] |
+ } |
+ set char [string map $escapes $char] |
+ set x [catchcmdex test.db ".print $char\n"] |
+ set code [lindex $x 0] |
+ set res [lindex $x 1] |
+ if {$code ne "0"} { |
+ error "failed with error: $res" |
+ } |
+ if {$res ne "$oldChar\n"} { |
+ error "failed with byte $hex mismatch" |
+ } |
+ } |
+} {} |
+ |
finish_test |