1*11da002cSdan# 2016 December 17 2*11da002cSdan# 3*11da002cSdan# The author disclaims copyright to this source code. In place of 4*11da002cSdan# a legal notice, here is a blessing: 5*11da002cSdan# 6*11da002cSdan# May you do good and not evil. 7*11da002cSdan# May you find forgiveness for yourself and forgive others. 8*11da002cSdan# May you share freely, never taking more than you give. 9*11da002cSdan# 10*11da002cSdan#*********************************************************************** 11*11da002cSdan# 12*11da002cSdan# Test the readfile() function built into the shell tool. Specifically, 13*11da002cSdan# that it does not truncate the blob read at the first embedded 0x00 14*11da002cSdan# byte. 15*11da002cSdan# 16*11da002cSdan 17*11da002cSdanset testdir [file dirname $argv0] 18*11da002cSdansource $testdir/tester.tcl 19*11da002cSdanset testprefix shell7 20*11da002cSdanset CLI [test_find_cli] 21*11da002cSdan 22*11da002cSdan 23*11da002cSdando_execsql_test 1.0 { 24*11da002cSdan CREATE TABLE f1(tn INTEGER PRIMARY KEY, x BLOB); 25*11da002cSdan CREATE TABLE f2(tn INTEGER PRIMARY KEY, x BLOB); 26*11da002cSdan 27*11da002cSdan INSERT INTO f1 VALUES(1, X'01020304'); 28*11da002cSdan INSERT INTO f1 VALUES(2, X'01000304'); 29*11da002cSdan INSERT INTO f1 VALUES(3, randomblob(200)); 30*11da002cSdan} 31*11da002cSdan 32*11da002cSdanforeach {tn l x} [db eval { SELECT tn, length(x) AS l, x FROM f1 }] { 33*11da002cSdan forcedelete shell7_test.bin 34*11da002cSdan set fd [open shell7_test.bin w] 35*11da002cSdan fconfigure $fd -encoding binary 36*11da002cSdan fconfigure $fd -translation binary 37*11da002cSdan puts -nonewline $fd $x 38*11da002cSdan close $fd 39*11da002cSdan 40*11da002cSdan do_test 1.$tn.1 { file size shell7_test.bin } $l 41*11da002cSdan do_test 1.$tn.2 { 42*11da002cSdan catchcmd test.db "INSERT INTO f2 VALUES($tn, readfile('shell7_test.bin'));" 43*11da002cSdan } {0 {}} 44*11da002cSdan 45*11da002cSdan do_execsql_test 1.$tn.3 { 46*11da002cSdan SELECT (SELECT x FROM f1 WHERE tn=1)==(SELECT x FROM f2 WHERE tn=1) 47*11da002cSdan } {1} 48*11da002cSdan} 49*11da002cSdan 50*11da002cSdan 51*11da002cSdan 52*11da002cSdanfinish_test 53