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 # $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix incrblob_err
19 ifcapable {!incrblob || !memdebug || !tclvar} {
24 source $testdir/malloc_common.tcl
26 unset -nocomplain ::fd ::data
27 set ::fd [open $::cmdlinearg(INFO_SCRIPT)]
28 set ::data [read $::fd]
31 do_malloc_test 1 -tclprep {
32 set bytes [file size $::cmdlinearg(INFO_SCRIPT)]
34 CREATE TABLE blobs(k, v BLOB);
35 INSERT INTO blobs VALUES(1, zeroblob($::bytes));
38 set ::blob [db incrblob blobs v 1]
39 fconfigure $::blob -translation binary
40 set rc [catch {puts -nonewline $::blob $::data}]
41 if {$rc} { error "out of memory" }
44 do_malloc_test 2 -tclprep {
46 CREATE TABLE blobs(k, v BLOB);
47 INSERT INTO blobs VALUES(1, $::data);
50 set ::blob [db incrblob blobs v 1]
51 set rc [catch {set ::r [read $::blob]}]
54 } elseif {$::r ne $::data} {
55 error "Bad data read..."
59 do_malloc_test 3 -tclprep {
61 CREATE TABLE blobs(k, v BLOB);
62 INSERT INTO blobs VALUES(1, $::data);
65 set ::blob [db incrblob blobs v 1]
66 set rc [catch {set ::r [read $::blob]}]
69 } elseif {$::r ne $::data} {
70 error "Bad data read..."
72 set rc [catch {close $::blob}]
78 do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
79 CREATE TABLE blobs(k, v BLOB);
80 INSERT INTO blobs VALUES(1, $::data);
82 set ::blob [db incrblob blobs v 1]
86 do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
87 CREATE TABLE blobs(k, v BLOB);
88 INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
90 set ::blob [db incrblob blobs v 1]
91 fconfigure $::blob -translation binary
92 puts -nonewline $::blob $::data
96 do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
97 CREATE TABLE blobs(k, v BLOB);
98 INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
100 set ::blob [db incrblob blobs v 1]
101 fconfigure $::blob -translation binary
103 puts -nonewline $::blob "12345678900987654321"
107 do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
108 PRAGMA auto_vacuum = 1;
109 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
110 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
112 # Read some data from the end of the large blob inserted into table
113 # "blobs". This forces the IO error to occur while reading a pointer
114 # map page for the purposes of seeking to the end of the blob.
117 set ::blob [db2 incrblob blobs v 1]
118 sqlite3_blob_read $::blob [expr 500*1020-20] 20
123 do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
124 PRAGMA auto_vacuum = 1;
125 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
126 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
128 # Read some data from the end of the large blob inserted into table
129 # "blobs". This forces the IO error to occur while reading a pointer
130 # map page for the purposes of seeking to the end of the blob.
133 set ::blob [db2 incrblob blobs v 1]
134 sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321