interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / shell7.test

96 lines · 2773 bytes Raw Blame History
1# 2016 December 17
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# TESTRUNNER: shell
12#
13# Test the readfile() function built into the shell tool. Specifically,
14# that it does not truncate the blob read at the first embedded 0x00
15# byte.
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20set testprefix shell7
21set CLI [test_find_cli]
22
23
24do_execsql_test 1.0 {
25 CREATE TABLE f1(tn INTEGER PRIMARY KEY, x BLOB);
26 CREATE TABLE f2(tn INTEGER PRIMARY KEY, x BLOB);
27
28 INSERT INTO f1 VALUES(1, X'01020304');
29 INSERT INTO f1 VALUES(2, X'01000304');
30 INSERT INTO f1 VALUES(3, randomblob(200));
31}
32
33foreach {tn l x} [db eval { SELECT tn, length(x) AS l, x FROM f1 }] {
34 forcedelete shell7_test.bin
35 set fd [open shell7_test.bin w]
36 fconfigure $fd -translation binary
37 puts -nonewline $fd $x
38 close $fd
39
40 do_test 1.$tn.1 { file size shell7_test.bin } $l
41 do_test 1.$tn.2 {
42 catchcmd test.db "INSERT INTO f2 VALUES($tn, readfile('shell7_test.bin'));"
43 } {0 {}}
44
45 do_execsql_test 1.$tn.3 {
46 SELECT (SELECT x FROM f1 WHERE tn=1)==(SELECT x FROM f2 WHERE tn=1)
47 } {1}
48}
49
50#--------------------------------------------------------------------------
51# Test that <https://sqlite.org/bugs/forumpost/e94b3920a3> is resolved.
52#
53if {[catch {db eval { SELECT * FROM dbstat }} msg]==0} {
54 do_execsql_test 2.0 {
55 CREATE TABLE t1(a, b);
56 CREATE INDEX i1 ON t1(b);
57 INSERT INTO t1 VALUES(1, 1), (2, 2);
58 }
59
60 do_test 2.1 {
61 catchcmd test.db "SELECT length( diskused('main') ) > 1000"
62 } {0 1}
63
64 do_execsql_test 2.2 {
65 CREATE TABLE "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q"(a, b);
66 INSERT INTO "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q" VALUES(10, 10), (20, 20);
67 CREATE INDEX i2 ON "t2_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q_%q"(b);
68 }
69
70 do_test 2.3 {
71 catchcmd test.db "SELECT length( diskused('main') ) > 1000"
72 } {0 1}
73
74 # https://sqlite.org/bugs/info/23d77b5d47908a41
75 # Very small percentages should not be shown in exponential notation.
76 #
77 do_test 2.4 {
78 forcedelete test2.db
79 sqlite3 db2 test2.db
80 db2 eval {
81 PRAGMA auto_vacuum=OFF;
82 PRAGMA page_size=4096;
83 CREATE TABLE t1(x);
84 INSERT INTO t1 VALUES(zeroblob(30000000));
85 DELETE FROM t1;
86 INSERT INTO t1 VALUES('x');
87 }
88 db2 close
89 set res [catchcmd test2.db ".diskused"]
90 list [lindex $res 0] [regexp {e-0} [lindex $res 1]] \
91 [regexp {<0\.0001%} [lindex $res 1]]
92 } {0 0 1}
93 forcedelete test2.db
94}
95
96finish_test