1# 2007 May 1 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# 12# $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $ 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set ::testprefix incrblob_err 18 19ifcapable {!incrblob || !tclvar} { 20 finish_test 21 return 22} 23 24source $testdir/malloc_common.tcl 25 26unset -nocomplain ::fd ::data 27set ::fd [open $::cmdlinearg(INFO_SCRIPT)] 28set ::data [read $::fd] 29close $::fd 30 31do_malloc_test 1 -tclprep { 32 set bytes [file size $::cmdlinearg(INFO_SCRIPT)] 33 execsql { 34 CREATE TABLE blobs(k, v BLOB); 35 INSERT INTO blobs VALUES(1, zeroblob($::bytes)); 36 } 37} -tclbody { 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" } 42} 43 44do_malloc_test 2 -tclprep { 45 execsql { 46 CREATE TABLE blobs(k, v BLOB); 47 INSERT INTO blobs VALUES(1, $::data); 48 } 49} -tclbody { 50 set ::blob [db incrblob blobs v 1] 51 set rc [catch {set ::r [read $::blob]}] 52 if {$rc} { 53 error "out of memory" 54 } elseif {$::r ne $::data} { 55 error "Bad data read..." 56 } 57} 58 59do_malloc_test 3 -tclprep { 60 execsql { 61 CREATE TABLE blobs(k, v BLOB); 62 INSERT INTO blobs VALUES(1, $::data); 63 } 64} -tclbody { 65 set ::blob [db incrblob blobs v 1] 66 set rc [catch {set ::r [read $::blob]}] 67 if {$rc} { 68 error "out of memory" 69 } elseif {$::r ne $::data} { 70 error "Bad data read..." 71 } 72 set rc [catch {close $::blob}] 73 if {$rc} { 74 error "out of memory" 75 } 76} 77 78do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep { 79 CREATE TABLE blobs(k, v BLOB); 80 INSERT INTO blobs VALUES(1, $::data); 81} -tclbody { 82 set ::blob [db incrblob blobs v 1] 83 read $::blob 84} 85 86do_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)))); 89} -tclbody { 90 set ::blob [db incrblob blobs v 1] 91 fconfigure $::blob -translation binary 92 puts -nonewline $::blob $::data 93 close $::blob 94} 95 96do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep { 97 CREATE TABLE blobs(k, v BLOB); 98 INSERT INTO blobs VALUES(1, $::data || $::data || $::data); 99} -tclbody { 100 set ::blob [db incrblob blobs v 1] 101 fconfigure $::blob -translation binary 102 seek $::blob -20 end 103 puts -nonewline $::blob "12345678900987654321" 104 close $::blob 105} 106 107do_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)); 111} -tclbody { 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. 115 # 116 sqlite3 db2 test.db 117 set ::blob [db2 incrblob blobs v 1] 118 sqlite3_blob_read $::blob [expr 500*1020-20] 20 119 close $::blob 120} 121catch {db2 close} 122 123do_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)); 127} -tclbody { 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. 131 # 132 sqlite3 db2 test.db 133 set ::blob [db2 incrblob blobs v 1] 134 sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321 135 close $::blob 136} 137 138catch {db2 close} 139 140finish_test 141