2007-05-04 16:05:56 +04:00
|
|
|
# 2007 May 1
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2008-07-18 21:16:26 +04:00
|
|
|
# $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $
|
2007-05-04 16:05:56 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2014-08-12 17:38:52 +04:00
|
|
|
set ::testprefix incrblob_err
|
2007-05-04 16:05:56 +04:00
|
|
|
|
2018-09-18 20:00:06 +03:00
|
|
|
ifcapable {!incrblob || !tclvar} {
|
2007-05-04 23:03:02 +04:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2007-08-25 17:09:26 +04:00
|
|
|
source $testdir/malloc_common.tcl
|
2007-05-04 16:05:56 +04:00
|
|
|
|
2008-06-25 18:31:53 +04:00
|
|
|
unset -nocomplain ::fd ::data
|
2016-03-14 20:05:04 +03:00
|
|
|
set ::fd [open $::cmdlinearg(INFO_SCRIPT)]
|
2007-05-04 16:05:56 +04:00
|
|
|
set ::data [read $::fd]
|
|
|
|
close $::fd
|
|
|
|
|
|
|
|
do_malloc_test 1 -tclprep {
|
2016-03-14 20:05:04 +03:00
|
|
|
set bytes [file size $::cmdlinearg(INFO_SCRIPT)]
|
2007-05-04 16:05:56 +04:00
|
|
|
execsql {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, zeroblob($::bytes));
|
|
|
|
}
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
2011-06-24 17:50:13 +04:00
|
|
|
fconfigure $::blob -translation binary
|
2007-05-04 16:05:56 +04:00
|
|
|
set rc [catch {puts -nonewline $::blob $::data}]
|
|
|
|
if {$rc} { error "out of memory" }
|
|
|
|
}
|
|
|
|
|
|
|
|
do_malloc_test 2 -tclprep {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, $::data);
|
|
|
|
}
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
|
|
|
set rc [catch {set ::r [read $::blob]}]
|
|
|
|
if {$rc} {
|
|
|
|
error "out of memory"
|
|
|
|
} elseif {$::r ne $::data} {
|
|
|
|
error "Bad data read..."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do_malloc_test 3 -tclprep {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, $::data);
|
|
|
|
}
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
|
|
|
set rc [catch {set ::r [read $::blob]}]
|
|
|
|
if {$rc} {
|
|
|
|
error "out of memory"
|
|
|
|
} elseif {$::r ne $::data} {
|
|
|
|
error "Bad data read..."
|
|
|
|
}
|
|
|
|
set rc [catch {close $::blob}]
|
|
|
|
if {$rc} {
|
|
|
|
error "out of memory"
|
|
|
|
}
|
2011-06-24 17:50:13 +04:00
|
|
|
}
|
2008-05-12 11:42:20 +04:00
|
|
|
|
2007-05-04 16:05:56 +04:00
|
|
|
do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, $::data);
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
|
|
|
read $::blob
|
|
|
|
}
|
|
|
|
|
|
|
|
do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
2011-06-24 17:50:13 +04:00
|
|
|
fconfigure $::blob -translation binary
|
2007-05-04 16:05:56 +04:00
|
|
|
puts -nonewline $::blob $::data
|
|
|
|
close $::blob
|
|
|
|
}
|
|
|
|
|
|
|
|
do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
|
|
|
|
CREATE TABLE blobs(k, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
|
|
|
|
} -tclbody {
|
|
|
|
set ::blob [db incrblob blobs v 1]
|
2011-06-24 17:50:13 +04:00
|
|
|
fconfigure $::blob -translation binary
|
2007-05-04 16:05:56 +04:00
|
|
|
seek $::blob -20 end
|
|
|
|
puts -nonewline $::blob "12345678900987654321"
|
|
|
|
close $::blob
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:07:32 +04:00
|
|
|
do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
|
|
|
|
PRAGMA auto_vacuum = 1;
|
|
|
|
CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
|
|
|
|
} -tclbody {
|
|
|
|
# Read some data from the end of the large blob inserted into table
|
|
|
|
# "blobs". This forces the IO error to occur while reading a pointer
|
|
|
|
# map page for the purposes of seeking to the end of the blob.
|
|
|
|
#
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
set ::blob [db2 incrblob blobs v 1]
|
|
|
|
sqlite3_blob_read $::blob [expr 500*1020-20] 20
|
|
|
|
close $::blob
|
|
|
|
}
|
2008-07-16 22:35:45 +04:00
|
|
|
catch {db2 close}
|
2008-07-08 16:07:32 +04:00
|
|
|
|
|
|
|
do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
|
|
|
|
PRAGMA auto_vacuum = 1;
|
|
|
|
CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
|
|
|
|
INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
|
|
|
|
} -tclbody {
|
|
|
|
# Read some data from the end of the large blob inserted into table
|
|
|
|
# "blobs". This forces the IO error to occur while reading a pointer
|
|
|
|
# map page for the purposes of seeking to the end of the blob.
|
|
|
|
#
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
set ::blob [db2 incrblob blobs v 1]
|
|
|
|
sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321
|
|
|
|
close $::blob
|
|
|
|
}
|
|
|
|
|
2008-07-18 21:16:26 +04:00
|
|
|
catch {db2 close}
|
2008-07-08 21:43:56 +04:00
|
|
|
|
2007-05-04 16:05:56 +04:00
|
|
|
finish_test
|