sl@0: # 2007 May 1 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable {!incrblob || !memdebug || !tclvar} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: source $testdir/malloc_common.tcl sl@0: sl@0: unset -nocomplain ::fd ::data sl@0: set ::fd [open [info script]] sl@0: set ::data [read $::fd] sl@0: close $::fd sl@0: sl@0: do_malloc_test 1 -tclprep { sl@0: set bytes [file size [info script]] sl@0: execsql { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, zeroblob($::bytes)); sl@0: } sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: set rc [catch {puts -nonewline $::blob $::data}] sl@0: if {$rc} { error "out of memory" } sl@0: } sl@0: sl@0: do_malloc_test 2 -tclprep { sl@0: execsql { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, $::data); sl@0: } sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: set rc [catch {set ::r [read $::blob]}] sl@0: if {$rc} { sl@0: error "out of memory" sl@0: } elseif {$::r ne $::data} { sl@0: error "Bad data read..." sl@0: } sl@0: } sl@0: sl@0: do_malloc_test 3 -tclprep { sl@0: execsql { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, $::data); sl@0: } sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: set rc [catch {set ::r [read $::blob]}] sl@0: if {$rc} { sl@0: error "out of memory" sl@0: } elseif {$::r ne $::data} { sl@0: error "Bad data read..." sl@0: } sl@0: set rc [catch {close $::blob}] sl@0: if {$rc} { sl@0: error "out of memory" sl@0: } sl@0: } sl@0: sl@0: sl@0: do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, $::data); sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: read $::blob sl@0: } sl@0: sl@0: do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB)))); sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: puts -nonewline $::blob $::data sl@0: close $::blob sl@0: } sl@0: sl@0: do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep { sl@0: CREATE TABLE blobs(k, v BLOB); sl@0: INSERT INTO blobs VALUES(1, $::data || $::data || $::data); sl@0: } -tclbody { sl@0: set ::blob [db incrblob blobs v 1] sl@0: seek $::blob -20 end sl@0: puts -nonewline $::blob "12345678900987654321" sl@0: close $::blob sl@0: } sl@0: sl@0: do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep { sl@0: PRAGMA auto_vacuum = 1; sl@0: CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB); sl@0: INSERT INTO blobs VALUES(1, zeroblob(500 * 1020)); sl@0: } -tclbody { sl@0: # Read some data from the end of the large blob inserted into table sl@0: # "blobs". This forces the IO error to occur while reading a pointer sl@0: # map page for the purposes of seeking to the end of the blob. sl@0: # sl@0: sqlite3 db2 test.db sl@0: set ::blob [db2 incrblob blobs v 1] sl@0: sqlite3_blob_read $::blob [expr 500*1020-20] 20 sl@0: close $::blob sl@0: } sl@0: catch {db2 close} sl@0: sl@0: do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep { sl@0: PRAGMA auto_vacuum = 1; sl@0: CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB); sl@0: INSERT INTO blobs VALUES(1, zeroblob(500 * 1020)); sl@0: } -tclbody { sl@0: # Read some data from the end of the large blob inserted into table sl@0: # "blobs". This forces the IO error to occur while reading a pointer sl@0: # map page for the purposes of seeking to the end of the blob. sl@0: # sl@0: sqlite3 db2 test.db sl@0: set ::blob [db2 incrblob blobs v 1] sl@0: sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321 sl@0: close $::blob sl@0: } sl@0: sl@0: catch {db2 close} sl@0: sl@0: finish_test