2009-11-10 20:07:30 +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.
|
|
|
|
#
|
|
|
|
# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
|
|
|
# shell2-1.*: Misc. test of various tickets and reported errors.
|
|
|
|
#
|
2012-04-24 16:46:05 +04:00
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2016-03-15 12:55:44 +03:00
|
|
|
set CLI [test_find_cli]
|
2012-04-24 16:46:05 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db test.db-journal test.db-wal
|
2009-11-10 20:07:30 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# shell2-1.*: Misc. test of various tickets and reported errors.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Batch mode not creating databases.
|
2009-11-11 07:17:07 +03:00
|
|
|
# Reported on mailing list by Ken Zalewski.
|
2009-11-10 20:07:30 +03:00
|
|
|
# Ticket [aeff892c57].
|
|
|
|
do_test shell2-1.1.1 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2009-11-11 07:17:07 +03:00
|
|
|
set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
|
2009-11-10 20:07:30 +03:00
|
|
|
set fexist [file exist foo.db]
|
|
|
|
list $rc $fexist
|
|
|
|
} {{0 {}} 1}
|
|
|
|
|
2009-11-11 07:17:07 +03:00
|
|
|
# Shell silently ignores extra parameters.
|
|
|
|
# Ticket [f5cb008a65].
|
|
|
|
do_test shell2-1.2.1 {
|
2021-09-19 21:31:55 +03:00
|
|
|
catchcmdex {:memory: "select+3" "select+4"}
|
2014-11-28 16:35:03 +03:00
|
|
|
} {0 {3
|
2021-09-19 21:31:55 +03:00
|
|
|
4
|
|
|
|
}}
|
2009-11-11 07:17:07 +03:00
|
|
|
|
2010-01-05 07:59:56 +03:00
|
|
|
# Test a problem reported on the mailing list. The shell was at one point
|
|
|
|
# returning the generic SQLITE_ERROR message ("SQL error or missing database")
|
|
|
|
# instead of the "too many levels..." message in the test below.
|
|
|
|
#
|
|
|
|
do_test shell2-1.3 {
|
|
|
|
catchcmd "-batch test.db" {
|
|
|
|
PRAGMA recursive_triggers = ON;
|
|
|
|
CREATE TABLE t5(a PRIMARY KEY, b, c);
|
|
|
|
INSERT INTO t5 VALUES(1, 2, 3);
|
|
|
|
CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
|
|
|
|
UPDATE OR IGNORE t5 SET a = new.a, c = 10;
|
|
|
|
END;
|
|
|
|
|
|
|
|
UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
|
|
|
|
}
|
2022-02-08 15:13:16 +03:00
|
|
|
} {1 {Runtime error near line 9: too many levels of trigger recursion}}
|
2009-12-18 00:07:54 +03:00
|
|
|
|
2009-11-11 07:17:07 +03:00
|
|
|
|
2010-01-18 21:17:10 +03:00
|
|
|
|
|
|
|
# Shell not echoing all commands with echo on.
|
|
|
|
# Ticket [eb620916be].
|
|
|
|
|
|
|
|
# Test with echo off
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.1 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2010-01-18 21:17:10 +03:00
|
|
|
catchcmd "foo.db" {CREATE TABLE foo(a);
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;}
|
|
|
|
} {0 1}
|
|
|
|
|
|
|
|
# Test with echo on using command line option
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.2 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2010-01-18 21:17:10 +03:00
|
|
|
catchcmd "-echo foo.db" {CREATE TABLE foo(a);
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;}
|
|
|
|
} {0 {CREATE TABLE foo(a);
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;
|
|
|
|
1}}
|
|
|
|
|
|
|
|
# Test with echo on using dot command
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.3 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2010-01-18 21:17:10 +03:00
|
|
|
catchcmd "foo.db" {.echo ON
|
|
|
|
CREATE TABLE foo(a);
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;}
|
|
|
|
} {0 {CREATE TABLE foo(a);
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;
|
|
|
|
1}}
|
|
|
|
|
|
|
|
# Test with echo on using dot command and
|
|
|
|
# turning off mid- processing.
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.4 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2010-01-18 21:17:10 +03:00
|
|
|
catchcmd "foo.db" {.echo ON
|
|
|
|
CREATE TABLE foo(a);
|
|
|
|
.echo OFF
|
|
|
|
INSERT INTO foo(a) VALUES(1);
|
|
|
|
SELECT * FROM foo;}
|
|
|
|
} {0 {CREATE TABLE foo(a);
|
|
|
|
.echo OFF
|
|
|
|
1}}
|
|
|
|
|
|
|
|
# Test with echo on using dot command and
|
|
|
|
# multiple commands per line.
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.5 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2021-09-19 21:31:55 +03:00
|
|
|
catchcmdex "foo.db" {.echo ON
|
2010-01-18 21:17:10 +03:00
|
|
|
CREATE TABLE foo1(a);
|
|
|
|
INSERT INTO foo1(a) VALUES(1);
|
|
|
|
CREATE TABLE foo2(b);
|
|
|
|
INSERT INTO foo2(b) VALUES(1);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
|
|
|
INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
|
|
|
}
|
|
|
|
} {0 {CREATE TABLE foo1(a);
|
|
|
|
INSERT INTO foo1(a) VALUES(1);
|
|
|
|
CREATE TABLE foo2(b);
|
|
|
|
INSERT INTO foo2(b) VALUES(1);
|
2022-05-11 22:59:31 +03:00
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
2010-01-18 21:17:10 +03:00
|
|
|
1
|
|
|
|
1
|
2022-05-11 22:59:31 +03:00
|
|
|
INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
2010-01-18 21:17:10 +03:00
|
|
|
1
|
|
|
|
2
|
|
|
|
1
|
2013-12-21 19:46:06 +04:00
|
|
|
2
|
|
|
|
}}
|
2010-01-18 21:17:10 +03:00
|
|
|
|
|
|
|
# Test with echo on and headers on using dot command and
|
|
|
|
# multiple commands per line.
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell2-1.4.6 {
|
2013-09-14 03:26:47 +04:00
|
|
|
forcedelete foo.db
|
2021-09-19 21:31:55 +03:00
|
|
|
catchcmdex "foo.db" {.echo ON
|
2010-01-18 21:17:10 +03:00
|
|
|
.headers ON
|
|
|
|
CREATE TABLE foo1(a);
|
|
|
|
INSERT INTO foo1(a) VALUES(1);
|
|
|
|
CREATE TABLE foo2(b);
|
|
|
|
INSERT INTO foo2(b) VALUES(1);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
|
|
|
INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
|
|
|
}
|
|
|
|
} {0 {.headers ON
|
|
|
|
CREATE TABLE foo1(a);
|
|
|
|
INSERT INTO foo1(a) VALUES(1);
|
|
|
|
CREATE TABLE foo2(b);
|
|
|
|
INSERT INTO foo2(b) VALUES(1);
|
2022-05-11 22:59:31 +03:00
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
2010-01-18 21:17:10 +03:00
|
|
|
a
|
|
|
|
1
|
|
|
|
b
|
|
|
|
1
|
2022-05-11 22:59:31 +03:00
|
|
|
INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
|
|
|
|
SELECT * FROM foo1; SELECT * FROM foo2;
|
2010-01-18 21:17:10 +03:00
|
|
|
a
|
|
|
|
1
|
|
|
|
2
|
|
|
|
b
|
|
|
|
1
|
2013-12-21 19:46:06 +04:00
|
|
|
2
|
|
|
|
}}
|
2010-07-19 19:01:43 +04:00
|
|
|
|
2022-03-15 20:57:42 +03:00
|
|
|
# Test for rejection of incomplete input at EOF.
|
|
|
|
# Reported at https://sqlite.org/forum/forumpost/718f489a43be3197
|
|
|
|
do_test shell2-1.4.7 {
|
|
|
|
catchcmd ":memory:" {
|
|
|
|
SELECT 'unclosed;}
|
|
|
|
} {1 {Parse error near line 2: unrecognized token: "'unclosed;"
|
|
|
|
SELECT 'unclosed;
|
|
|
|
^--- error here}}
|
|
|
|
|
2022-12-05 02:20:38 +03:00
|
|
|
# Verify that safe mode rejects certain UDFs
|
|
|
|
# Reported at https://sqlite.org/forum/forumpost/07beac8056151b2f
|
|
|
|
do_test shell2-1.4.8 {
|
|
|
|
catchcmd "-safe :memory:" {
|
|
|
|
SELECT edit('DoNotCare');}
|
|
|
|
} {1 {line 2: cannot use the edit() function in safe mode}}
|
|
|
|
do_test shell2-1.4.9 {
|
|
|
|
catchcmd "-safe :memory:" {
|
|
|
|
SELECT writefile('DoNotCare', x'');}
|
|
|
|
} {1 {line 2: cannot use the writefile() function in safe mode}}
|
|
|
|
|
2023-01-17 00:49:37 +03:00
|
|
|
# Verify that .clone handles sequence table.
|
|
|
|
# See https://sqlite.org/forum/forumpost/71ff9e6c4c
|
|
|
|
do_test shell2-1.4.9 {
|
|
|
|
forcedelete clone.db
|
|
|
|
set res [catchcmd :memory: [string trim {
|
|
|
|
CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT);
|
|
|
|
INSERT INTO t VALUES (1),(2);
|
|
|
|
.clone clone.db
|
|
|
|
.open clone.db
|
|
|
|
SELECT max(seq) FROM sqlite_sequence;}]]
|
|
|
|
} {0 {t... done
|
|
|
|
done
|
|
|
|
2}}
|
|
|
|
|
2023-04-29 02:39:16 +03:00
|
|
|
# Verify that generate_series stays sane near 64-bit range boundaries.
|
|
|
|
# See overflow report at https://sqlite.org/forum/forumpost/5d34ce5280
|
|
|
|
do_test shell2-1.4.10 {
|
|
|
|
set res [catchcmd :memory: [string trim {
|
|
|
|
SELECT * FROM generate_series(9223372036854775807,9223372036854775807,1);
|
|
|
|
SELECT * FROM generate_series(9223372036854775807,9223372036854775807,-1);
|
2023-04-29 18:29:29 +03:00
|
|
|
SELECT avg(rowid),min(value),max(value) FROM generate_series(
|
|
|
|
-9223372036854775808,9223372036854775807,1085102592571150095);
|
2023-04-29 02:39:16 +03:00
|
|
|
SELECT * FROM generate_series(-9223372036854775808,9223372036854775807,
|
|
|
|
9223372036854775807);
|
|
|
|
SELECT value,rowid FROM generate_series(-4611686018427387904,
|
|
|
|
4611686018427387904, 4611686018427387904) ORDER BY value DESC;
|
|
|
|
SELECT * FROM generate_series(0,-2,-1);
|
|
|
|
SELECT * FROM generate_series(0,-2);
|
|
|
|
SELECT * FROM generate_series(0,2) LIMIT 3;}]]
|
|
|
|
} {0 {9223372036854775807
|
|
|
|
9223372036854775807
|
2023-04-29 18:29:29 +03:00
|
|
|
9.5|-9223372036854775808|9223372036854775807
|
2023-04-29 02:39:16 +03:00
|
|
|
-9223372036854775808
|
|
|
|
-1
|
|
|
|
9223372036854775806
|
|
|
|
4611686018427387904|3
|
|
|
|
0|2
|
|
|
|
-4611686018427387904|1
|
|
|
|
0
|
|
|
|
-1
|
|
|
|
-2
|
|
|
|
0
|
|
|
|
1
|
|
|
|
2}}
|
2022-12-05 02:20:38 +03:00
|
|
|
|
2023-05-02 21:03:25 +03:00
|
|
|
# Bug discovered while messing around, .import hangs with
|
|
|
|
# bit 7 set in column separator.
|
|
|
|
do_test shell2-1.4.11 {
|
|
|
|
forcedelete dummy.csv
|
|
|
|
set df [open dummy.csv w]
|
|
|
|
puts $df dog,cat
|
|
|
|
close $df
|
|
|
|
set res [catchcmd :memory: [string trim {
|
|
|
|
CREATE TABLE t(line text);
|
|
|
|
.mode ascii
|
|
|
|
.separator "\377" "\n"
|
|
|
|
.import dummy.csv t
|
|
|
|
SELECT count(*) FROM t;}]]
|
|
|
|
} {0 1}
|
|
|
|
|
2023-06-26 20:08:08 +03:00
|
|
|
# Bug from forum post 7cbe081746dd3803
|
|
|
|
# Keywords as column names were producing an error message.
|
|
|
|
do_test shell2-1.4.12 {
|
|
|
|
set res [catchcmd :memory: [string trim {
|
|
|
|
CREATE TABLE "group"("order" text);
|
|
|
|
INSERT INTO "group" VALUES ('ABC');
|
|
|
|
.sha3sum}]]
|
|
|
|
} {0 ca08bc02b7e95c7df431a3a4b1cc0f8d8743914793473f55b5558e03}
|
|
|
|
|
2023-05-02 21:03:25 +03:00
|
|
|
|
2012-04-24 16:46:05 +04:00
|
|
|
finish_test
|