Files
sqlite/test/shell7.test
drh 0b97f1b101 Test case tweaks to account for different configurations.
FossilOrigin-Name: 46476df942c3684665e66f9e2cb7e7fa6a1822d1f059969cca91a6b665c4eea0
2026-10-26 15:18:19 +00:00

97 lines
2.7 KiB
Plaintext

# 2016 December 17
#
# 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.
#
#***********************************************************************
# TESTRUNNER: shell
#
# Test the readfile() function built into the shell tool. Specifically,
# that it does not truncate the blob read at the first embedded 0x00
# byte.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix shell7
set CLI [test_find_cli]
do_execsql_test 1.0 {
CREATE TABLE f1(tn INTEGER PRIMARY KEY, x BLOB);
CREATE TABLE f2(tn INTEGER PRIMARY KEY, x BLOB);
INSERT INTO f1 VALUES(1, X'01020304');
INSERT INTO f1 VALUES(2, X'01000304');
INSERT INTO f1 VALUES(3, randomblob(200));
}
foreach {tn l x} [db eval { SELECT tn, length(x) AS l, x FROM f1 }] {
forcedelete shell7_test.bin
set fd [open shell7_test.bin w]
fconfigure $fd -translation binary
puts -nonewline $fd $x
close $fd
do_test 1.$tn.1 { file size shell7_test.bin } $l
do_test 1.$tn.2 {
catchcmd test.db "INSERT INTO f2 VALUES($tn, readfile('shell7_test.bin'));"
} {0 {}}
do_execsql_test 1.$tn.3 {
SELECT (SELECT x FROM f1 WHERE tn=1)==(SELECT x FROM f2 WHERE tn=1)
} {1}
}
#--------------------------------------------------------------------------
# Test that <https://sqlite.org/bugs/forumpost/e94b3920a3> is resolved.
#
if {[catch {db eval { SELECT * FROM dbstat }} msg]==0} {
do_execsql_test 2.0 {
CREATE TABLE t1(a, b);
CREATE INDEX i1 ON t1(b);
INSERT INTO t1 VALUES(1, 1), (2, 2);
}
do_test 2.1 {
catchcmd test.db "SELECT length( diskused('main') ) > 1000"
} {0 1}
do_execsql_test 2.2 {
CREATE TABLE "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q"(a, b);
INSERT INTO "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q" VALUES(10, 10), (20, 20);
CREATE INDEX i2 ON "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q"(b);
}
do_test 2.3 {
catchcmd test.db "SELECT length( diskused('main') ) > 1000"
} {0 1}
# https://sqlite.org/bugs/info/23d77b5d47908a41
# Very small percentages should not be shown in exponential notation.
#
do_test 2.4 {
forcedelete test2.db
sqlite3 db2 test2.db
db2 eval {
PRAGMA auto_vacuum=OFF;
PRAGMA page_size=4096;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(zeroblob(30000000));
DELETE FROM t1;
INSERT INTO t1 VALUES('x');
}
db2 close
set res [catchcmd test2.db ".diskused"]
list [lindex $res 0] [regexp {e-0} [lindex $res 1]] \
[regexp {<0\.0001%} [lindex $res 1]]
} {0 0 1}
forcedelete test2.db
}
finish_test