2009-11-06 06:22:54 +03:00
|
|
|
# 2009 Nov 11
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
# The focus of this file is testing the CLI shell tool.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
2009-11-11 07:17:07 +03:00
|
|
|
# shell1-1.*: Basic command line option handling.
|
|
|
|
# shell1-2.*: Basic "dot" command token parsing.
|
|
|
|
# shell1-3.*: Basic test that "dot" command can be called.
|
2021-10-04 01:03:59 +03:00
|
|
|
# shell1-{4-8}.*: Test various "dot" commands's functionality.
|
|
|
|
# shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
|
2009-11-06 06:22:54 +03:00
|
|
|
#
|
2012-04-24 16:46:05 +04:00
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2022-05-09 15:29:47 +03:00
|
|
|
set CLI [test_cli_invocation]
|
2012-04-24 16:46:05 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db test.db-journal test.db-wal
|
2009-11-06 06:22:54 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
2009-11-11 07:17:07 +03:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Test cases shell1-1.*: Basic command line option handling.
|
|
|
|
#
|
|
|
|
|
|
|
|
# invalid option
|
|
|
|
do_test shell1-1.1.1 {
|
|
|
|
set res [catchcmd "-bad test.db" ""]
|
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
|
|
|
[regexp {Error: unknown option: -bad} $res]
|
|
|
|
} {1 1}
|
2014-11-28 16:35:03 +03:00
|
|
|
do_test shell1-1.1.1b {
|
|
|
|
set res [catchcmd "test.db -bad" ""]
|
2009-11-11 07:17:07 +03:00
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
2014-11-28 16:35:03 +03:00
|
|
|
[regexp {Error: unknown option: -bad} $res]
|
2009-11-11 07:17:07 +03:00
|
|
|
} {1 1}
|
|
|
|
# error on extra options
|
2014-11-28 16:35:03 +03:00
|
|
|
do_test shell1-1.1.2 {
|
2016-03-26 18:36:36 +03:00
|
|
|
catchcmd "test.db \"select+3\" \"select+4\"" ""
|
2014-11-28 16:35:03 +03:00
|
|
|
} {0 {3
|
|
|
|
4}}
|
|
|
|
# error on extra options
|
2009-12-18 00:07:54 +03:00
|
|
|
do_test shell1-1.1.3 {
|
2014-11-28 16:35:03 +03:00
|
|
|
catchcmd "test.db FOO test.db BAD" ".quit"
|
2022-02-08 15:13:16 +03:00
|
|
|
} {/1 .Error: in prepare, near "FOO": syntax error*/}
|
2009-11-11 07:17:07 +03:00
|
|
|
|
|
|
|
# -help
|
|
|
|
do_test shell1-1.2.1 {
|
|
|
|
set res [catchcmd "-help test.db" ""]
|
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
|
|
|
[regexp {Usage} $res] \
|
|
|
|
[regexp {\-init} $res] \
|
|
|
|
[regexp {\-version} $res]
|
|
|
|
} {1 1 1 1}
|
|
|
|
|
|
|
|
# -init filename read/process named file
|
2020-11-25 16:59:47 +03:00
|
|
|
forcedelete FOO
|
|
|
|
set out [open FOO w]
|
|
|
|
puts $out ""
|
|
|
|
close $out
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-1.3.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "-init FOO test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.3.2 {
|
2014-11-28 16:35:03 +03:00
|
|
|
catchcmd "-init FOO test.db .quit BAD" ""
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.3.3 {
|
|
|
|
catchcmd "-init FOO test.db BAD .quit" ""
|
2022-02-08 15:13:16 +03:00
|
|
|
} {/1 .Error: in prepare, near "BAD": syntax error*/}
|
2009-11-11 07:17:07 +03:00
|
|
|
|
|
|
|
# -echo print commands before execution
|
|
|
|
do_test shell1-1.4.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-echo test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -[no]header turn headers on or off
|
|
|
|
do_test shell1-1.5.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-header test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.5.2 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-noheader test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -bail stop after hitting an error
|
|
|
|
do_test shell1-1.6.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-bail test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -interactive force interactive I/O
|
|
|
|
do_test shell1-1.7.1 {
|
|
|
|
set res [catchcmd "-interactive test.db" ".quit"]
|
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
|
|
|
[regexp {SQLite version} $res] \
|
2014-02-11 20:22:18 +04:00
|
|
|
[regexp {Enter ".help" for usage hints} $res]
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 1 1}
|
|
|
|
|
|
|
|
# -batch force batch I/O
|
|
|
|
do_test shell1-1.8.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-batch test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -column set output mode to 'column'
|
|
|
|
do_test shell1-1.9.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-column test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -csv set output mode to 'csv'
|
|
|
|
do_test shell1-1.10.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-csv test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -html set output mode to HTML
|
|
|
|
do_test shell1-1.11.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-html test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -line set output mode to 'line'
|
|
|
|
do_test shell1-1.12.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-line test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -list set output mode to 'list'
|
|
|
|
do_test shell1-1.13.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-list test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# -separator 'x' set output field separator (|)
|
|
|
|
do_test shell1-1.14.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-separator 'x' test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.14.2 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-separator x test.db" ""
|
2009-11-11 07:17:07 +03:00
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.14.3 {
|
|
|
|
set res [catchcmd "-separator" ""]
|
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
2012-10-25 19:23:14 +04:00
|
|
|
[regexp {Error: missing argument to -separator} $res]
|
2009-11-11 07:17:07 +03:00
|
|
|
} {1 1}
|
|
|
|
|
2010-07-28 20:05:34 +04:00
|
|
|
# -stats print memory stats before each finalize
|
|
|
|
do_test shell1-1.14b.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "-stats test.db" ""
|
2010-07-28 20:05:34 +04:00
|
|
|
} {0 {}}
|
|
|
|
|
2009-11-11 07:17:07 +03:00
|
|
|
# -nullvalue 'text' set text string for NULL values
|
|
|
|
do_test shell1-1.15.1 {
|
|
|
|
catchcmd "-nullvalue 'x' test.db" ""
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.15.2 {
|
|
|
|
catchcmd "-nullvalue x test.db" ""
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-1.15.3 {
|
|
|
|
set res [catchcmd "-nullvalue" ""]
|
|
|
|
set rc [lindex $res 0]
|
|
|
|
list $rc \
|
2012-10-25 19:23:14 +04:00
|
|
|
[regexp {Error: missing argument to -nullvalue} $res]
|
2009-11-11 07:17:07 +03:00
|
|
|
} {1 1}
|
|
|
|
|
|
|
|
# -version show SQLite version
|
|
|
|
do_test shell1-1.16.1 {
|
2011-06-03 17:28:22 +04:00
|
|
|
set x [catchcmd "-version test.db" ""]
|
2012-05-22 02:45:35 +04:00
|
|
|
} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
|
2009-11-06 20:20:17 +03:00
|
|
|
|
2009-11-06 06:22:54 +03:00
|
|
|
#----------------------------------------------------------------------------
|
2009-11-11 07:17:07 +03:00
|
|
|
# Test cases shell1-2.*: Basic "dot" command token parsing.
|
2009-11-06 06:22:54 +03:00
|
|
|
#
|
|
|
|
|
2009-11-06 20:20:17 +03:00
|
|
|
# check first token handling
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.1.1 {
|
2016-04-04 05:16:44 +03:00
|
|
|
catchcmd "test.db" ".foo"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.1.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\"foo OFF\""
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.1.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\'foo OFF\'"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
|
|
|
|
|
|
|
|
# unbalanced quotes
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\"foo OFF"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\'foo OFF"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain \"OFF"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.4 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain \'OFF"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.5 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode \"insert FOO"
|
2022-02-01 15:28:17 +03:00
|
|
|
} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.2.6 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode \'insert FOO"
|
2022-02-01 15:28:17 +03:00
|
|
|
} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
|
2009-11-06 20:20:17 +03:00
|
|
|
|
|
|
|
# check multiple tokens, and quoted tokens
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain 1"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain on"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain \"1 2 3\""
|
2013-01-28 22:18:26 +04:00
|
|
|
} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.4 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain \"OFF\""
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.5 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\'explain\' \'OFF\'"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.6 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain \'OFF\'"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.3.7 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".\'explain\' \'OFF\'"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# check quoted args are unquoted
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.4.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode FOO"
|
2022-02-01 15:28:17 +03:00
|
|
|
} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.4.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode csv"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-2.4.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode \"csv\""
|
2009-11-06 20:20:17 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
2009-11-11 07:17:07 +03:00
|
|
|
# Test cases shell1-3.*: Basic test that "dot" command can be called.
|
2009-11-06 20:20:17 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
# .backup ?DB? FILE Backup DB (default "main") to FILE
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.1.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".backup"
|
2013-01-23 22:53:23 +04:00
|
|
|
} {1 {missing FILENAME argument on .backup}}
|
2020-11-25 17:50:42 +03:00
|
|
|
forcedelete FOO
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.1.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".backup FOO"
|
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.1.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".backup FOO BAR"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown database FOO}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.1.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".backup FOO BAR BAD"
|
2018-12-10 03:41:28 +03:00
|
|
|
} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .bail ON|OFF Stop after hitting an error. Default OFF
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.2.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".bail"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .bail on|off}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.2.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".bail ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.2.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".bail OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.2.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".bail OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .bail on|off}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2016-12-27 05:43:47 +03:00
|
|
|
ifcapable vtab {
|
2009-11-06 06:22:54 +03:00
|
|
|
# .databases List names and files of attached databases
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.3.1 {
|
2016-03-26 17:41:13 +03:00
|
|
|
catchcmd "-csv test.db" ".databases"
|
2016-03-26 16:26:35 +03:00
|
|
|
} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.3.2 {
|
2014-05-29 16:36:14 +04:00
|
|
|
# extra arguments ignored
|
2016-03-26 17:41:13 +03:00
|
|
|
catchcmd "test.db" ".databases BAD"
|
2016-03-26 16:26:35 +03:00
|
|
|
} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
|
2016-12-27 05:43:47 +03:00
|
|
|
}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .dump ?TABLE? ... Dump the database in an SQL text format
|
|
|
|
# If TABLE specified, only dump tables matching
|
|
|
|
# LIKE pattern TABLE.
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.4.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
set res [catchcmd "test.db" ".dump"]
|
2009-11-06 06:22:54 +03:00
|
|
|
list [regexp {BEGIN TRANSACTION;} $res] \
|
|
|
|
[regexp {COMMIT;} $res]
|
|
|
|
} {1 1}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.4.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
set res [catchcmd "test.db" ".dump FOO"]
|
2009-11-06 06:22:54 +03:00
|
|
|
list [regexp {BEGIN TRANSACTION;} $res] \
|
|
|
|
[regexp {COMMIT;} $res]
|
|
|
|
} {1 1}
|
2020-03-25 15:50:13 +03:00
|
|
|
# The .dump command now accepts multiple arguments
|
|
|
|
#do_test shell1-3.4.3 {
|
|
|
|
# # too many arguments
|
|
|
|
# catchcmd "test.db" ".dump FOO BAD"
|
|
|
|
#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .echo ON|OFF Turn command echo on or off
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.5.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".echo"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .echo on|off}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.5.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".echo ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.5.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".echo OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.5.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".echo OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .echo on|off}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .exit Exit this program
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.6.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".exit"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
|
|
|
|
|
|
|
# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.7.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain"
|
2009-11-06 20:20:17 +03:00
|
|
|
# explain is the exception to the booleans. without an option, it turns it on.
|
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.7.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.7.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.7.4 {
|
2014-05-29 16:36:14 +04:00
|
|
|
# extra arguments ignored
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".explain OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
# .header(s) ON|OFF Turn display of headers on or off
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".header"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .headers on|off}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".header ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".header OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".header OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .headers on|off}}
|
2009-11-06 20:20:17 +03:00
|
|
|
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.5 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".headers"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .headers on|off}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.6 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".headers ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.7 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".headers OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.9.8 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".headers OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .headers on|off}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .help Show this message
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.10.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
set res [catchcmd "test.db" ".help"]
|
2009-11-06 06:22:54 +03:00
|
|
|
# look for a few of the possible help commands
|
|
|
|
list [regexp {.help} $res] \
|
|
|
|
[regexp {.quit} $res] \
|
|
|
|
[regexp {.show} $res]
|
|
|
|
} {1 1 1}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.10.2 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# we allow .help to take extra args (it is help after all)
|
2018-09-26 19:53:51 +03:00
|
|
|
set res [catchcmd "test.db" ".help *"]
|
2009-11-06 20:20:17 +03:00
|
|
|
# look for a few of the possible help commands
|
|
|
|
list [regexp {.help} $res] \
|
|
|
|
[regexp {.quit} $res] \
|
|
|
|
[regexp {.show} $res]
|
|
|
|
} {1 1 1}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .import FILE TABLE Import data from FILE into TABLE
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.11.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".import"
|
2020-03-09 18:39:39 +03:00
|
|
|
} {/1 .ERROR: missing FILE argument.*/}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.11.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".import FOO"
|
2020-03-09 18:39:39 +03:00
|
|
|
} {/1 .ERROR: missing TABLE argument.*/}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.11.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".import FOO BAR BAD"
|
2020-03-09 18:39:39 +03:00
|
|
|
} {/1 .ERROR: extra argument: "BAD".*./}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2015-02-06 17:51:13 +03:00
|
|
|
# .indexes ?TABLE? Show names of all indexes
|
|
|
|
# If TABLE specified, only show indexes for tables
|
2009-11-06 06:22:54 +03:00
|
|
|
# matching LIKE pattern TABLE.
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.12.1 {
|
2015-02-06 17:51:13 +03:00
|
|
|
catchcmd "test.db" ".indexes"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.12.2 {
|
2015-02-06 17:51:13 +03:00
|
|
|
catchcmd "test.db" ".indexes FOO"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-3.12.2-legacy {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".indices FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.12.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2015-02-06 17:51:13 +03:00
|
|
|
catchcmd "test.db" ".indexes FOO BAD"
|
|
|
|
} {1 {Usage: .indexes ?LIKE-PATTERN?}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .mode MODE ?TABLE? Set output mode where MODE is one of:
|
2014-12-11 06:12:33 +03:00
|
|
|
# ascii Columns/rows delimited by 0x1F and 0x1E
|
2009-11-06 06:22:54 +03:00
|
|
|
# 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
|
2014-12-11 06:12:33 +03:00
|
|
|
# list Values delimited by .separator strings
|
2009-11-06 06:22:54 +03:00
|
|
|
# tabs Tab-separated values
|
|
|
|
# tcl TCL list elements
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode"
|
2017-06-30 00:33:25 +03:00
|
|
|
} {0 {current output mode: list}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode FOO"
|
2022-02-01 15:28:17 +03:00
|
|
|
} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode csv"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.4 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode column"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.5 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode html"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.6 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode insert"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.7 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode line"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.8 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode list"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.9 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode tabs"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.10 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode tcl"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.13.11 {
|
2014-05-29 16:36:14 +04:00
|
|
|
# extra arguments ignored
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".mode tcl BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 20:20:17 +03:00
|
|
|
|
2009-11-06 06:22:54 +03:00
|
|
|
# .nullvalue STRING Print STRING in place of NULL values
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.14.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".nullvalue"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .nullvalue STRING}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.14.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".nullvalue FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.14.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".nullvalue FOO BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .nullvalue STRING}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .output FILENAME Send output to FILENAME
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.15.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".output"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.15.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".output FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.15.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".output FOO BAD"
|
2020-04-20 19:21:30 +03:00
|
|
|
} {1 {ERROR: extra parameter: "BAD". Usage:
|
|
|
|
.output ?FILE? Send output to FILE or stdout if FILE is omitted
|
|
|
|
If FILE begins with '|' then open it as a pipe.
|
|
|
|
Options:
|
|
|
|
--bom Prefix output with a UTF8 byte-order mark
|
|
|
|
-e Send output to the system text editor
|
|
|
|
-x Send output as CSV to a spreadsheet
|
|
|
|
child process exited abnormally}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .output stdout Send output to the screen
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.16.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".output stdout"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.16.2 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".output stdout BAD"
|
2020-04-20 19:21:30 +03:00
|
|
|
} {1 {ERROR: extra parameter: "BAD". Usage:
|
|
|
|
.output ?FILE? Send output to FILE or stdout if FILE is omitted
|
|
|
|
If FILE begins with '|' then open it as a pipe.
|
|
|
|
Options:
|
|
|
|
--bom Prefix output with a UTF8 byte-order mark
|
|
|
|
-e Send output to the system text editor
|
|
|
|
-x Send output as CSV to a spreadsheet
|
|
|
|
child process exited abnormally}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .prompt MAIN CONTINUE Replace the standard prompts
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.17.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".prompt"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.17.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".prompt FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.17.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".prompt FOO BAR"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.17.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".prompt FOO BAR BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .quit Exit this program
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.18.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".quit"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.18.2 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".quit BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .read FILENAME Execute SQL in FILENAME
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.19.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".read"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .read FILE}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.19.2 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete FOO
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".read FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {1 {Error: cannot open "FOO"}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.19.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".read FOO BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .read FILE}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .restore ?DB? FILE Restore content of DB (default "main") from FILE
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.20.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".restore"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .restore ?DB? FILE}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.20.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".restore FOO"
|
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.20.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".restore FOO BAR"
|
2009-11-06 20:20:17 +03:00
|
|
|
} {1 {Error: unknown database FOO}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.20.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".restore FOO BAR BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .restore ?DB? FILE}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2017-06-24 22:21:48 +03:00
|
|
|
ifcapable vtab {
|
2009-11-06 06:22:54 +03:00
|
|
|
# .schema ?TABLE? Show the CREATE statements
|
|
|
|
# If TABLE specified, only show tables matching
|
|
|
|
# LIKE pattern TABLE.
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.21.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".schema"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.21.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".schema FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.21.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".schema FOO BAD"
|
2020-10-12 17:56:47 +03:00
|
|
|
} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2012-05-21 07:15:06 +04:00
|
|
|
do_test shell1-3.21.4 {
|
|
|
|
catchcmd "test.db" {
|
|
|
|
CREATE TABLE t1(x);
|
|
|
|
CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
|
|
|
|
CREATE VIEW v1 AS SELECT y+1 FROM v2;
|
|
|
|
}
|
|
|
|
catchcmd "test.db" ".schema"
|
|
|
|
} {0 {CREATE TABLE t1(x);
|
2018-01-02 00:28:25 +03:00
|
|
|
CREATE VIEW v2 AS SELECT x+1 AS y FROM t1
|
2018-01-02 00:49:43 +03:00
|
|
|
/* v2(y) */;
|
2018-01-02 00:28:25 +03:00
|
|
|
CREATE VIEW v1 AS SELECT y+1 FROM v2
|
2018-01-02 00:49:43 +03:00
|
|
|
/* v1("y+1") */;}}
|
2022-02-11 04:21:09 +03:00
|
|
|
|
|
|
|
catch {db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}}
|
2017-06-24 22:21:48 +03:00
|
|
|
}
|
2012-05-21 07:15:06 +04:00
|
|
|
|
2014-07-20 00:15:16 +04:00
|
|
|
# .separator STRING Change column separator used by output and .import
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.22.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".separator"
|
2014-12-11 06:12:33 +03:00
|
|
|
} {1 {Usage: .separator COL ?ROW?}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.22.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".separator FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.22.3 {
|
2014-07-24 16:09:47 +04:00
|
|
|
catchcmd "test.db" ".separator ABC XYZ"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-3.22.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2014-07-24 16:09:47 +04:00
|
|
|
catchcmd "test.db" ".separator FOO BAD BAD2"
|
2014-12-11 06:12:33 +03:00
|
|
|
} {1 {Usage: .separator COL ?ROW?}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .show Show the current values for various settings
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.23.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
set res [catchcmd "test.db" ".show"]
|
2009-11-06 06:22:54 +03:00
|
|
|
list [regexp {echo:} $res] \
|
|
|
|
[regexp {explain:} $res] \
|
|
|
|
[regexp {headers:} $res] \
|
|
|
|
[regexp {mode:} $res] \
|
|
|
|
[regexp {nullvalue:} $res] \
|
|
|
|
[regexp {output:} $res] \
|
2014-07-20 00:15:16 +04:00
|
|
|
[regexp {colseparator:} $res] \
|
|
|
|
[regexp {rowseparator:} $res] \
|
2010-07-28 20:05:34 +04:00
|
|
|
[regexp {stats:} $res] \
|
2009-11-06 06:22:54 +03:00
|
|
|
[regexp {width:} $res]
|
2014-12-11 06:12:33 +03:00
|
|
|
} {1 1 1 1 1 1 1 1 1 1}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.23.2 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".show BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .show}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2010-07-28 20:05:34 +04:00
|
|
|
# .stats ON|OFF Turn stats on or off
|
2016-02-27 20:12:36 +03:00
|
|
|
#do_test shell1-3.23b.1 {
|
|
|
|
# catchcmd "test.db" ".stats"
|
2021-01-09 22:10:04 +03:00
|
|
|
#} {1 {Usage: .stats on|off|stmt|vmstep}}
|
2010-07-28 20:05:34 +04:00
|
|
|
do_test shell1-3.23b.2 {
|
|
|
|
catchcmd "test.db" ".stats ON"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-3.23b.3 {
|
|
|
|
catchcmd "test.db" ".stats OFF"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell1-3.23b.4 {
|
|
|
|
# too many arguments
|
|
|
|
catchcmd "test.db" ".stats OFF BAD"
|
2021-01-09 22:10:04 +03:00
|
|
|
} {1 {Usage: .stats ?on|off|stmt|vmstep?}}
|
2010-07-28 20:05:34 +04:00
|
|
|
|
2018-06-07 18:23:43 +03:00
|
|
|
# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07
|
|
|
|
# Adverse interaction between .stats and .eqp
|
|
|
|
#
|
|
|
|
do_test shell1-3.23b.5 {
|
|
|
|
catchcmd "test.db" [string map {"\n " "\n"} {
|
|
|
|
CREATE TEMP TABLE t1(x);
|
|
|
|
INSERT INTO t1 VALUES(1),(2);
|
|
|
|
.stats on
|
|
|
|
.eqp full
|
|
|
|
SELECT * FROM t1;
|
|
|
|
}]
|
|
|
|
} {/1\n2\n/}
|
|
|
|
|
2009-11-06 06:22:54 +03:00
|
|
|
# .tables ?TABLE? List names of tables
|
|
|
|
# If TABLE specified, only list tables matching
|
|
|
|
# LIKE pattern TABLE.
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.24.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".tables"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.24.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".tables FOO"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.24.3 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".tables FOO BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .timeout MS Try opening locked tables for MS milliseconds
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.25.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timeout"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.25.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timeout zzz"
|
2009-11-06 20:20:17 +03:00
|
|
|
# this should be treated the same as a '0' timeout
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.25.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timeout 1"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.25.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timeout 1 BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .width NUM NUM ... Set column widths for "column" mode
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.26.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".width"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.26.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".width xxx"
|
2009-11-06 20:20:17 +03:00
|
|
|
# this should be treated the same as a '0' width for col 1
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.26.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".width xxx yyy"
|
2009-11-06 20:20:17 +03:00
|
|
|
# this should be treated the same as a '0' width for col 1 and 2
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.26.4 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".width 1 1"
|
2009-11-06 20:20:17 +03:00
|
|
|
# this should be treated the same as a '1' width for col 1 and 2
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2012-09-21 17:40:02 +04:00
|
|
|
do_test shell1-3.26.5 {
|
2020-06-05 03:54:27 +03:00
|
|
|
catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;"
|
2012-09-21 17:40:02 +04:00
|
|
|
# this should be treated the same as a '1' width for col 1 and 2
|
|
|
|
} {0 {abcdefg 123456}}
|
|
|
|
do_test shell1-3.26.6 {
|
2020-06-05 03:54:27 +03:00
|
|
|
catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
|
2012-09-21 17:40:02 +04:00
|
|
|
# this should be treated the same as a '1' width for col 1 and 2
|
|
|
|
} {0 { abcdefg 123456 }}
|
|
|
|
|
2009-11-06 06:22:54 +03:00
|
|
|
|
|
|
|
# .timer ON|OFF Turn the CPU timer measurement on or off
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.27.1 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timer"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .timer on|off}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.27.2 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timer ON"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.27.3 {
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timer OFF"
|
2009-11-06 06:22:54 +03:00
|
|
|
} {0 {}}
|
2009-11-11 07:17:07 +03:00
|
|
|
do_test shell1-3.27.4 {
|
2009-11-06 20:20:17 +03:00
|
|
|
# too many arguments
|
2009-12-18 00:07:54 +03:00
|
|
|
catchcmd "test.db" ".timer OFF BAD"
|
2014-05-29 16:36:14 +04:00
|
|
|
} {1 {Usage: .timer on|off}}
|
2009-11-06 06:22:54 +03:00
|
|
|
|
2011-04-25 22:20:04 +04:00
|
|
|
do_test shell1-3-28.1 {
|
|
|
|
catchcmd test.db \
|
|
|
|
".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
|
|
|
|
} "0 {(123) hello\n456}"
|
|
|
|
|
2012-09-21 17:40:02 +04:00
|
|
|
do_test shell1-3-29.1 {
|
|
|
|
catchcmd "test.db" ".print this is a test"
|
|
|
|
} {0 {this is a test}}
|
|
|
|
|
2013-06-27 17:26:55 +04:00
|
|
|
# dot-command argument quoting
|
|
|
|
do_test shell1-3-30.1 {
|
|
|
|
catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
|
|
|
|
} {0 {this"is'a-test this\"is\\a\055test}}
|
|
|
|
do_test shell1-3-31.1 {
|
|
|
|
catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
|
|
|
|
} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
|
|
|
|
|
|
|
|
|
2012-04-24 17:14:49 +04:00
|
|
|
# Test the output of the ".dump" command
|
|
|
|
#
|
|
|
|
do_test shell1-4.1 {
|
2013-09-04 20:08:50 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db
|
|
|
|
sqlite3 db test.db
|
2012-04-24 17:14:49 +04:00
|
|
|
db eval {
|
2013-09-04 20:08:50 +04:00
|
|
|
PRAGMA encoding=UTF16;
|
2012-04-24 17:14:49 +04:00
|
|
|
CREATE TABLE t1(x);
|
2012-12-04 04:23:43 +04:00
|
|
|
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
|
2015-04-08 00:16:40 +03:00
|
|
|
CREATE TABLE t3(x,y);
|
|
|
|
INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
|
|
|
|
(4,2.25), (5,'hello'), (6,x'807f');
|
2012-04-24 17:14:49 +04:00
|
|
|
}
|
|
|
|
catchcmd test.db {.dump}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(x);
|
2017-03-08 15:25:18 +03:00
|
|
|
INSERT INTO t1 VALUES(NULL);
|
|
|
|
INSERT INTO t1 VALUES('');
|
|
|
|
INSERT INTO t1 VALUES(1);
|
|
|
|
INSERT INTO t1 VALUES(2.25);
|
|
|
|
INSERT INTO t1 VALUES('hello');
|
|
|
|
INSERT INTO t1 VALUES(X'807f');
|
2015-04-08 00:16:40 +03:00
|
|
|
CREATE TABLE t3(x,y);
|
2017-03-08 15:25:18 +03:00
|
|
|
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');
|
2012-04-24 17:14:49 +04:00
|
|
|
COMMIT;}}
|
|
|
|
|
2017-03-25 21:31:42 +03:00
|
|
|
|
|
|
|
ifcapable vtab {
|
|
|
|
|
2017-03-08 15:25:18 +03:00
|
|
|
# The --preserve-rowids option to .dump
|
|
|
|
#
|
2017-03-08 14:44:00 +03:00
|
|
|
do_test shell1-4.1.1 {
|
|
|
|
catchcmd test.db {.dump --preserve-rowids}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(x);
|
2017-03-08 15:25:18 +03:00
|
|
|
INSERT INTO t1(rowid,x) VALUES(1,NULL);
|
|
|
|
INSERT INTO t1(rowid,x) VALUES(2,'');
|
|
|
|
INSERT INTO t1(rowid,x) VALUES(3,1);
|
|
|
|
INSERT INTO t1(rowid,x) VALUES(4,2.25);
|
|
|
|
INSERT INTO t1(rowid,x) VALUES(5,'hello');
|
|
|
|
INSERT INTO t1(rowid,x) VALUES(6,X'807f');
|
2017-03-08 14:44:00 +03:00
|
|
|
CREATE TABLE t3(x,y);
|
2017-03-08 15:25:18 +03:00
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
|
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(2,2,'');
|
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(3,3,1);
|
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
|
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
|
|
|
|
INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
|
2017-03-08 14:44:00 +03:00
|
|
|
COMMIT;}}
|
|
|
|
|
2017-03-08 15:25:18 +03:00
|
|
|
# If the table contains an INTEGER PRIMARY KEY, do not record a separate
|
|
|
|
# rowid column in the output.
|
|
|
|
#
|
2017-03-08 14:44:00 +03:00
|
|
|
do_test shell1-4.1.2 {
|
|
|
|
db close
|
|
|
|
forcedelete test2.db
|
|
|
|
sqlite3 db test2.db
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
|
|
|
|
INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
|
|
|
|
(4,2.25), (5,'hello'), (6,x'807f');
|
|
|
|
}
|
|
|
|
catchcmd test2.db {.dump --preserve-rowids}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
|
2017-03-08 15:25:18 +03:00
|
|
|
INSERT INTO t1 VALUES(1,NULL);
|
|
|
|
INSERT INTO t1 VALUES(2,'');
|
|
|
|
INSERT INTO t1 VALUES(3,1);
|
|
|
|
INSERT INTO t1 VALUES(4,2.25);
|
|
|
|
INSERT INTO t1 VALUES(5,'hello');
|
|
|
|
INSERT INTO t1 VALUES(6,X'807f');
|
|
|
|
COMMIT;}}
|
|
|
|
|
|
|
|
# Verify that the table named [table] is correctly quoted and that
|
|
|
|
# an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
|
|
|
|
#
|
|
|
|
do_test shell1-4.1.3 {
|
|
|
|
db close
|
|
|
|
forcedelete test2.db
|
|
|
|
sqlite3 db test2.db
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
|
|
|
|
INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
|
|
|
|
(34,2.25), (45,'hello'), (56,x'807f');
|
|
|
|
}
|
|
|
|
catchcmd test2.db {.dump --preserve-rowids}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
|
|
|
|
INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
|
2017-03-08 14:44:00 +03:00
|
|
|
COMMIT;}}
|
|
|
|
|
2017-03-08 15:25:18 +03:00
|
|
|
# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting
|
|
|
|
# of table names that contain odd characters.
|
|
|
|
#
|
|
|
|
do_test shell1-4.1.4 {
|
|
|
|
db close
|
|
|
|
forcedelete test2.db
|
|
|
|
sqlite3 db test2.db
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
|
|
|
|
INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
|
|
|
|
(34,2.25), (45,'hello'), (56,x'807f');
|
|
|
|
}
|
|
|
|
catchcmd test2.db {.dump --preserve-rowids}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
|
|
|
|
INSERT INTO "ta<>ble" VALUES(1,NULL);
|
|
|
|
INSERT INTO "ta<>ble" VALUES(12,'');
|
|
|
|
INSERT INTO "ta<>ble" VALUES(23,1);
|
|
|
|
INSERT INTO "ta<>ble" VALUES(34,2.25);
|
|
|
|
INSERT INTO "ta<>ble" VALUES(45,'hello');
|
|
|
|
INSERT INTO "ta<>ble" VALUES(56,X'807f');
|
|
|
|
COMMIT;}}
|
|
|
|
|
|
|
|
# Do not record rowids if the rowid is inaccessible
|
|
|
|
#
|
|
|
|
do_test shell1-4.1.5 {
|
|
|
|
db close
|
|
|
|
forcedelete test2.db
|
|
|
|
sqlite3 db test2.db
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t1(_ROWID_,rowid,oid);
|
|
|
|
INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
|
|
|
|
}
|
|
|
|
catchcmd test2.db {.dump --preserve-rowids}
|
|
|
|
} {0 {PRAGMA foreign_keys=OFF;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE t1(_ROWID_,rowid,oid);
|
|
|
|
INSERT INTO t1 VALUES(1,NULL,'alpha');
|
|
|
|
INSERT INTO t1 VALUES(12,'',99);
|
|
|
|
INSERT INTO t1 VALUES(23,1,X'b0b1b2');
|
|
|
|
COMMIT;}}
|
2017-03-08 14:44:00 +03:00
|
|
|
|
2017-03-25 21:31:42 +03:00
|
|
|
} else {
|
|
|
|
|
|
|
|
do_test shell1-4.1.6 {
|
|
|
|
db close
|
|
|
|
forcedelete test2.db
|
|
|
|
sqlite3 db test2.db
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
|
|
|
|
INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
|
|
|
|
(4,2.25), (5,'hello'), (6,x'807f');
|
|
|
|
}
|
|
|
|
catchcmd test2.db {.dump --preserve-rowids}
|
|
|
|
} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-24 17:14:49 +04:00
|
|
|
# Test the output of ".mode insert"
|
|
|
|
#
|
2015-04-08 00:16:40 +03:00
|
|
|
do_test shell1-4.2.1 {
|
2012-04-24 17:14:49 +04:00
|
|
|
catchcmd test.db ".mode insert t1\nselect * from t1;"
|
|
|
|
} {0 {INSERT INTO t1 VALUES(NULL);
|
2012-12-04 04:23:43 +04:00
|
|
|
INSERT INTO t1 VALUES('');
|
2012-04-24 17:14:49 +04:00
|
|
|
INSERT INTO t1 VALUES(1);
|
|
|
|
INSERT INTO t1 VALUES(2.25);
|
|
|
|
INSERT INTO t1 VALUES('hello');
|
|
|
|
INSERT INTO t1 VALUES(X'807f');}}
|
|
|
|
|
2015-04-08 00:16:40 +03:00
|
|
|
# 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
|
|
|
|
#
|
2015-04-08 00:17:53 +03:00
|
|
|
do_test shell1-4.2.4 {
|
2015-04-08 00:16:40 +03:00
|
|
|
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');}}
|
|
|
|
|
2012-12-04 04:23:43 +04:00
|
|
|
# Test the output of ".mode tcl"
|
|
|
|
#
|
|
|
|
do_test shell1-4.3 {
|
2013-09-04 20:08:50 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db
|
|
|
|
sqlite3 db test.db
|
|
|
|
db eval {
|
|
|
|
PRAGMA encoding=UTF8;
|
|
|
|
CREATE TABLE t1(x);
|
|
|
|
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
|
|
|
|
}
|
2012-12-04 04:23:43 +04:00
|
|
|
catchcmd test.db ".mode tcl\nselect * from t1;"
|
|
|
|
} {0 {""
|
|
|
|
""
|
|
|
|
"1"
|
|
|
|
"2.25"
|
|
|
|
"hello"
|
|
|
|
"\200\177"}}
|
|
|
|
|
|
|
|
# Test the output of ".mode tcl" with multiple columns
|
|
|
|
#
|
|
|
|
do_test shell1-4.4 {
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE t2(x,y);
|
|
|
|
INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
|
|
|
|
}
|
|
|
|
catchcmd test.db ".mode tcl\nselect * from t2;"
|
|
|
|
} {0 {"" ""
|
|
|
|
"1" "2.25"
|
|
|
|
"hello" "\200\177"}}
|
|
|
|
|
|
|
|
# Test the output of ".mode tcl" with ".nullvalue"
|
|
|
|
#
|
|
|
|
do_test shell1-4.5 {
|
|
|
|
catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
|
|
|
|
} {0 {"NULL" ""
|
|
|
|
"1" "2.25"
|
|
|
|
"hello" "\200\177"}}
|
|
|
|
|
|
|
|
# Test the output of ".mode tcl" with Tcl reserved characters
|
|
|
|
#
|
|
|
|
do_test shell1-4.6 {
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE tcl1(x);
|
|
|
|
INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
|
|
|
|
}
|
|
|
|
foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
|
|
|
|
list $x $y [llength $y]
|
|
|
|
} {0 {"\""
|
|
|
|
"["
|
|
|
|
"]"
|
|
|
|
"\\{"
|
|
|
|
"\\}"
|
|
|
|
";"
|
|
|
|
"$"} 7}
|
2012-04-24 17:14:49 +04:00
|
|
|
|
2022-01-03 22:33:44 +03:00
|
|
|
# Test the output of ".mode quote"
|
|
|
|
#
|
|
|
|
do_test shell1-4.7 {
|
|
|
|
catchcmd test.db ".mode quote\nselect x'0123456789ABCDEF';"
|
|
|
|
} {0 X'0123456789abcdef'}
|
|
|
|
|
2015-01-18 08:35:01 +03:00
|
|
|
# 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} {
|
|
|
|
#
|
2015-01-18 12:02:57 +03:00
|
|
|
# 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.
|
2015-01-18 08:35:01 +03:00
|
|
|
#
|
2015-01-18 12:02:57 +03:00
|
|
|
if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
|
2015-01-18 08:35:01 +03:00
|
|
|
continue
|
|
|
|
}
|
2019-04-12 19:25:42 +03:00
|
|
|
# Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests.
|
|
|
|
if {$i>=0x80 && $i<=0x9f} continue
|
2016-07-25 17:20:01 +03:00
|
|
|
if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue
|
2016-07-29 07:12:18 +03:00
|
|
|
if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue
|
2015-01-18 08:35:01 +03:00
|
|
|
set hex [format %02X $i]
|
|
|
|
set char [subst \\x$hex]; set oldChar $char
|
2015-01-20 00:11:31 +03:00
|
|
|
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]
|
2015-01-20 00:27:46 +03:00
|
|
|
set x [catchcmdex test.db ".print $char\n"]
|
2015-01-18 08:35:01 +03:00
|
|
|
set code [lindex $x 0]
|
|
|
|
set res [lindex $x 1]
|
|
|
|
if {$code ne "0"} {
|
|
|
|
error "failed with error: $res"
|
|
|
|
}
|
|
|
|
if {$res ne "$oldChar\n"} {
|
2016-04-04 20:59:37 +03:00
|
|
|
if {[llength $res] > 0} {
|
|
|
|
set got [format %02X [scan $res %c]]
|
|
|
|
} else {
|
|
|
|
set got <empty>
|
|
|
|
}
|
|
|
|
error "failed with byte $hex mismatch, got $got"
|
2015-01-18 08:35:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
2016-05-16 14:55:09 +03:00
|
|
|
# These test cases do not work on MinGW
|
|
|
|
if 0 {
|
|
|
|
|
2016-04-04 18:47:46 +03:00
|
|
|
# The string used here is the word "test" in Chinese.
|
|
|
|
# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
|
|
|
|
set test \u6D4B\u8BD5
|
|
|
|
|
2016-04-04 05:16:44 +03:00
|
|
|
do_test shell1-6.0 {
|
2016-04-04 18:47:46 +03:00
|
|
|
set fileName $test; append fileName .db
|
|
|
|
catch {forcedelete $fileName}
|
2016-04-04 05:16:44 +03:00
|
|
|
set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
|
|
|
|
set code [lindex $x 0]
|
|
|
|
set res [string trim [lindex $x 1]]
|
|
|
|
if {$code ne "0"} {
|
|
|
|
error "failed with error: $res"
|
|
|
|
}
|
|
|
|
if {$res ne "CREATE TABLE t1(x);"} {
|
|
|
|
error "failed with mismatch: $res"
|
|
|
|
}
|
|
|
|
if {![file exists $fileName]} {
|
2016-04-04 05:33:34 +03:00
|
|
|
error "file \"$fileName\" (Unicode) does not exist"
|
2016-04-04 05:16:44 +03:00
|
|
|
}
|
|
|
|
forcedelete $fileName
|
|
|
|
} {}
|
|
|
|
|
2016-04-04 18:47:46 +03:00
|
|
|
do_test shell1-6.1 {
|
|
|
|
catch {forcedelete test3.db}
|
|
|
|
set x [catchcmdex test3.db \
|
|
|
|
"CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
|
|
|
|
set code [lindex $x 0]
|
|
|
|
set res [string trim [lindex $x 1]]
|
|
|
|
if {$code ne "0"} {
|
|
|
|
error "failed with error: $res"
|
|
|
|
}
|
|
|
|
if {$res ne "CREATE TABLE ${test}(x);"} {
|
|
|
|
error "failed with mismatch: $res"
|
|
|
|
}
|
|
|
|
forcedelete test3.db
|
|
|
|
} {}
|
2016-05-16 14:55:09 +03:00
|
|
|
}
|
2016-04-04 18:47:46 +03:00
|
|
|
|
2018-03-23 17:24:34 +03:00
|
|
|
db close
|
|
|
|
forcedelete test.db test.db-journal test.db-wal
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2018-03-24 18:08:48 +03:00
|
|
|
# The shell tool ".schema" command uses virtual table "pragma_database_list"
|
|
|
|
#
|
|
|
|
ifcapable vtab {
|
|
|
|
|
2018-03-23 17:24:34 +03:00
|
|
|
do_test shell1-7.1.1 {
|
|
|
|
db eval {
|
|
|
|
CREATE TABLE Z (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE _ (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE YY (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE __ (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE WWW (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE ___ (x TEXT PRIMARY KEY);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test shell1-7.1.2 {
|
|
|
|
catchcmd "test.db" ".schema _"
|
|
|
|
} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE _ (x TEXT PRIMARY KEY);}}
|
|
|
|
do_test shell1-7.1.3 {
|
|
|
|
catchcmd "test.db" ".schema \\\\_"
|
|
|
|
} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}}
|
|
|
|
do_test shell1-7.1.4 {
|
|
|
|
catchcmd "test.db" ".schema __"
|
|
|
|
} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE __ (x TEXT PRIMARY KEY);}}
|
|
|
|
do_test shell1-7.1.5 {
|
|
|
|
catchcmd "test.db" ".schema \\\\_\\\\_"
|
|
|
|
} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}}
|
|
|
|
do_test shell1-7.1.6 {
|
|
|
|
catchcmd "test.db" ".schema ___"
|
|
|
|
} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY);
|
|
|
|
CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
|
|
|
|
do_test shell1-7.1.7 {
|
|
|
|
catchcmd "test.db" ".schema \\\\_\\\\_\\\\_"
|
|
|
|
} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
|
|
|
|
|
2018-03-24 18:08:48 +03:00
|
|
|
}
|
|
|
|
|
2020-08-11 21:17:04 +03:00
|
|
|
# Test case for the ieee754 and decimal extensions in the shell.
|
|
|
|
# See the "floatingpoint.html" file in the documentation for more
|
|
|
|
# information.
|
|
|
|
#
|
|
|
|
do_test shell1-8.1 {
|
|
|
|
catchcmd ":memory:" {
|
|
|
|
-- The pow2 table will hold all the necessary powers of two.
|
|
|
|
CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
|
|
|
|
WITH RECURSIVE c(x,v) AS (
|
|
|
|
VALUES(0,'1')
|
|
|
|
UNION ALL
|
|
|
|
SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
|
|
|
|
) INSERT INTO pow2(x,v) SELECT x, v FROM c;
|
|
|
|
WITH RECURSIVE c(x,v) AS (
|
|
|
|
VALUES(-1,'0.5')
|
|
|
|
UNION ALL
|
|
|
|
SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
|
|
|
|
) INSERT INTO pow2(x,v) SELECT x, v FROM c;
|
|
|
|
|
|
|
|
-- This query finds the decimal representation of each value in the "c" table.
|
|
|
|
WITH c(n) AS (VALUES(47.49))
|
|
|
|
----XXXXX----------- Replace with whatever you want
|
|
|
|
SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
|
|
|
|
FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
|
|
|
|
}
|
|
|
|
} {0 47.49000000000000198951966012828052043914794921875}
|
|
|
|
do_test shell1-8.2 {
|
|
|
|
catchcmd :memory: {
|
|
|
|
.mode box
|
|
|
|
SELECT ieee754(47.49) AS x;
|
|
|
|
}
|
|
|
|
} {0 {┌───────────────────────────────┐
|
|
|
|
│ x │
|
|
|
|
├───────────────────────────────┤
|
|
|
|
│ ieee754(6683623321994527,-47) │
|
|
|
|
└───────────────────────────────┘}}
|
|
|
|
do_test shell1-8.3 {
|
|
|
|
catchcmd ":memory: --box" {
|
|
|
|
select ieee754(6683623321994527,-47) as x;
|
|
|
|
}
|
|
|
|
} {0 {┌───────┐
|
|
|
|
│ x │
|
|
|
|
├───────┤
|
|
|
|
│ 47.49 │
|
|
|
|
└───────┘}}
|
|
|
|
do_test shell1-8.4 {
|
|
|
|
catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
|
|
|
|
} {0 {+------------------+-----+
|
|
|
|
| M | E |
|
|
|
|
+------------------+-----+
|
|
|
|
| 6683623321994527 | -47 |
|
|
|
|
+------------------+-----+}}
|
2022-04-21 01:41:10 +03:00
|
|
|
do_test shell1-8.5 {
|
|
|
|
catchcmd ":memory: --box" {
|
|
|
|
create table t(a text, b int);
|
|
|
|
insert into t values ('too long for one line', 1), ('shorter', NULL);
|
|
|
|
.header on
|
|
|
|
.width 10 10
|
|
|
|
.nullvalue NADA
|
|
|
|
select * from t;}
|
|
|
|
} {0 {┌────────────┬────────────┐
|
|
|
|
│ a │ b │
|
|
|
|
├────────────┼────────────┤
|
|
|
|
│ too long f │ 1 │
|
|
|
|
│ or one lin │ │
|
|
|
|
│ e │ │
|
|
|
|
├────────────┼────────────┤
|
|
|
|
│ shorter │ NADA │
|
|
|
|
└────────────┴────────────┘}}
|
2020-08-11 21:17:04 +03:00
|
|
|
|
2021-10-04 01:03:59 +03:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
|
|
|
|
#
|
|
|
|
do_test shell1-9.1 {
|
|
|
|
catchcmd :memory: {
|
|
|
|
.mode csv
|
|
|
|
/*
|
|
|
|
x */ select 1,2; --x
|
|
|
|
-- .nada
|
|
|
|
;
|
|
|
|
.mode csv
|
|
|
|
--x
|
|
|
|
select 2,1; select 3,4;
|
|
|
|
}
|
|
|
|
} {0 {1,2
|
|
|
|
2,1
|
|
|
|
3,4}}
|
|
|
|
|
2022-12-23 22:04:59 +03:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Test cases shell1-10.*: Test that certain static extensions are there.
|
|
|
|
#
|
|
|
|
do_test shell1-10.1 {
|
|
|
|
catchcmd :memory: {
|
|
|
|
.mode list
|
|
|
|
.header off
|
|
|
|
select base64(base64(cast('digity-doo' as blob))),
|
|
|
|
base85(base85(cast('digity-doo' as blob)));
|
|
|
|
}
|
|
|
|
} {0 digity-doo|digity-doo}
|
|
|
|
|
2012-04-24 16:46:05 +04:00
|
|
|
finish_test
|