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
18 ifcapable {!incrblob || !memdebug || !tclvar} {
23 source $testdir/malloc_common.tcl
25 unset -nocomplain ::fd ::data
26 set ::fd [open [info script]]
27 set ::data [read $::fd]
30 do_malloc_test 1 -tclprep {
31 set bytes [file size [info script]]
33 CREATE TABLE blobs(k, v BLOB);
34 INSERT INTO blobs VALUES(1, zeroblob($::bytes));
37 set ::blob [db incrblob blobs v 1]
38 set rc [catch {puts -nonewline $::blob $::data}]
39 if {$rc} { error "out of memory" }
42 do_malloc_test 2 -tclprep {
44 CREATE TABLE blobs(k, v BLOB);
45 INSERT INTO blobs VALUES(1, $::data);
48 set ::blob [db incrblob blobs v 1]
49 set rc [catch {set ::r [read $::blob]}]
52 } elseif {$::r ne $::data} {
53 error "Bad data read..."
57 do_malloc_test 3 -tclprep {
59 CREATE TABLE blobs(k, v BLOB);
60 INSERT INTO blobs VALUES(1, $::data);
63 set ::blob [db incrblob blobs v 1]
64 set rc [catch {set ::r [read $::blob]}]
67 } elseif {$::r ne $::data} {
68 error "Bad data read..."
70 set rc [catch {close $::blob}]
77 do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
78 CREATE TABLE blobs(k, v BLOB);
79 INSERT INTO blobs VALUES(1, $::data);
81 set ::blob [db incrblob blobs v 1]
85 do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
86 CREATE TABLE blobs(k, v BLOB);
87 INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
89 set ::blob [db incrblob blobs v 1]
90 puts -nonewline $::blob $::data
94 do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
95 CREATE TABLE blobs(k, v BLOB);
96 INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
98 set ::blob [db incrblob blobs v 1]
100 puts -nonewline $::blob "12345678900987654321"
104 do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
105 PRAGMA auto_vacuum = 1;
106 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
107 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
109 # Read some data from the end of the large blob inserted into table
110 # "blobs". This forces the IO error to occur while reading a pointer
111 # map page for the purposes of seeking to the end of the blob.
114 set ::blob [db2 incrblob blobs v 1]
115 sqlite3_blob_read $::blob [expr 500*1020-20] 20
120 do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
121 PRAGMA auto_vacuum = 1;
122 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
123 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
125 # Read some data from the end of the large blob inserted into table
126 # "blobs". This forces the IO error to occur while reading a pointer
127 # map page for the purposes of seeking to the end of the blob.
130 set ::blob [db2 incrblob blobs v 1]
131 sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321