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 fconfigure $::blob -translation binary
39 set rc [catch {puts -nonewline $::blob $::data}]
40 if {$rc} { error "out of memory" }
43 do_malloc_test 2 -tclprep {
45 CREATE TABLE blobs(k, v BLOB);
46 INSERT INTO blobs VALUES(1, $::data);
49 set ::blob [db incrblob blobs v 1]
50 set rc [catch {set ::r [read $::blob]}]
53 } elseif {$::r ne $::data} {
54 error "Bad data read..."
58 do_malloc_test 3 -tclprep {
60 CREATE TABLE blobs(k, v BLOB);
61 INSERT INTO blobs VALUES(1, $::data);
64 set ::blob [db incrblob blobs v 1]
65 set rc [catch {set ::r [read $::blob]}]
68 } elseif {$::r ne $::data} {
69 error "Bad data read..."
71 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 fconfigure $::blob -translation binary
91 puts -nonewline $::blob $::data
95 do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
96 CREATE TABLE blobs(k, v BLOB);
97 INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
99 set ::blob [db incrblob blobs v 1]
100 fconfigure $::blob -translation binary
102 puts -nonewline $::blob "12345678900987654321"
106 do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
107 PRAGMA auto_vacuum = 1;
108 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
109 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
111 # Read some data from the end of the large blob inserted into table
112 # "blobs". This forces the IO error to occur while reading a pointer
113 # map page for the purposes of seeking to the end of the blob.
116 set ::blob [db2 incrblob blobs v 1]
117 sqlite3_blob_read $::blob [expr 500*1020-20] 20
122 do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
123 PRAGMA auto_vacuum = 1;
124 CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
125 INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
127 # Read some data from the end of the large blob inserted into table
128 # "blobs". This forces the IO error to occur while reading a pointer
129 # map page for the purposes of seeking to the end of the blob.
132 set ::blob [db2 incrblob blobs v 1]
133 sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321