Convert the implementation of the ".dbstat" dot-command of the command-line
[sqlite.git] / test / shell7.test
blob898018d775e2348c6e6e53fc155c600e010b56d7
1 # 2016 December 17
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Test the readfile() function built into the shell tool. Specifically,
13 # that it does not truncate the blob read at the first embedded 0x00
14 # byte.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix shell7
20 set CLI [test_find_cli]
23 do_execsql_test 1.0 { 
24   CREATE TABLE f1(tn INTEGER PRIMARY KEY, x BLOB); 
25   CREATE TABLE f2(tn INTEGER PRIMARY KEY, x BLOB); 
27   INSERT INTO f1 VALUES(1, X'01020304');
28   INSERT INTO f1 VALUES(2, X'01000304');
29   INSERT INTO f1 VALUES(3, randomblob(200));
32 foreach {tn l x} [db eval { SELECT tn, length(x) AS l, x FROM f1 }] {
33   forcedelete shell7_test.bin
34   set fd [open shell7_test.bin w]
35   fconfigure $fd -encoding binary
36   fconfigure $fd -translation binary
37   puts -nonewline $fd $x
38   close $fd
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 {}}
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}
52 finish_test