sl@0
|
1 |
# 2007 May 1
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $
|
sl@0
|
13 |
#
|
sl@0
|
14 |
|
sl@0
|
15 |
set testdir [file dirname $argv0]
|
sl@0
|
16 |
source $testdir/tester.tcl
|
sl@0
|
17 |
|
sl@0
|
18 |
ifcapable {!incrblob || !memdebug || !tclvar} {
|
sl@0
|
19 |
finish_test
|
sl@0
|
20 |
return
|
sl@0
|
21 |
}
|
sl@0
|
22 |
|
sl@0
|
23 |
source $testdir/malloc_common.tcl
|
sl@0
|
24 |
|
sl@0
|
25 |
unset -nocomplain ::fd ::data
|
sl@0
|
26 |
set ::fd [open [info script]]
|
sl@0
|
27 |
set ::data [read $::fd]
|
sl@0
|
28 |
close $::fd
|
sl@0
|
29 |
|
sl@0
|
30 |
do_malloc_test 1 -tclprep {
|
sl@0
|
31 |
set bytes [file size [info script]]
|
sl@0
|
32 |
execsql {
|
sl@0
|
33 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
34 |
INSERT INTO blobs VALUES(1, zeroblob($::bytes));
|
sl@0
|
35 |
}
|
sl@0
|
36 |
} -tclbody {
|
sl@0
|
37 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
38 |
set rc [catch {puts -nonewline $::blob $::data}]
|
sl@0
|
39 |
if {$rc} { error "out of memory" }
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
do_malloc_test 2 -tclprep {
|
sl@0
|
43 |
execsql {
|
sl@0
|
44 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
45 |
INSERT INTO blobs VALUES(1, $::data);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
} -tclbody {
|
sl@0
|
48 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
49 |
set rc [catch {set ::r [read $::blob]}]
|
sl@0
|
50 |
if {$rc} {
|
sl@0
|
51 |
error "out of memory"
|
sl@0
|
52 |
} elseif {$::r ne $::data} {
|
sl@0
|
53 |
error "Bad data read..."
|
sl@0
|
54 |
}
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
do_malloc_test 3 -tclprep {
|
sl@0
|
58 |
execsql {
|
sl@0
|
59 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
60 |
INSERT INTO blobs VALUES(1, $::data);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
} -tclbody {
|
sl@0
|
63 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
64 |
set rc [catch {set ::r [read $::blob]}]
|
sl@0
|
65 |
if {$rc} {
|
sl@0
|
66 |
error "out of memory"
|
sl@0
|
67 |
} elseif {$::r ne $::data} {
|
sl@0
|
68 |
error "Bad data read..."
|
sl@0
|
69 |
}
|
sl@0
|
70 |
set rc [catch {close $::blob}]
|
sl@0
|
71 |
if {$rc} {
|
sl@0
|
72 |
error "out of memory"
|
sl@0
|
73 |
}
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
|
sl@0
|
78 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
79 |
INSERT INTO blobs VALUES(1, $::data);
|
sl@0
|
80 |
} -tclbody {
|
sl@0
|
81 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
82 |
read $::blob
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
|
sl@0
|
86 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
87 |
INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
|
sl@0
|
88 |
} -tclbody {
|
sl@0
|
89 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
90 |
puts -nonewline $::blob $::data
|
sl@0
|
91 |
close $::blob
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
|
sl@0
|
95 |
CREATE TABLE blobs(k, v BLOB);
|
sl@0
|
96 |
INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
|
sl@0
|
97 |
} -tclbody {
|
sl@0
|
98 |
set ::blob [db incrblob blobs v 1]
|
sl@0
|
99 |
seek $::blob -20 end
|
sl@0
|
100 |
puts -nonewline $::blob "12345678900987654321"
|
sl@0
|
101 |
close $::blob
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
|
sl@0
|
105 |
PRAGMA auto_vacuum = 1;
|
sl@0
|
106 |
CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
|
sl@0
|
107 |
INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
|
sl@0
|
108 |
} -tclbody {
|
sl@0
|
109 |
# Read some data from the end of the large blob inserted into table
|
sl@0
|
110 |
# "blobs". This forces the IO error to occur while reading a pointer
|
sl@0
|
111 |
# map page for the purposes of seeking to the end of the blob.
|
sl@0
|
112 |
#
|
sl@0
|
113 |
sqlite3 db2 test.db
|
sl@0
|
114 |
set ::blob [db2 incrblob blobs v 1]
|
sl@0
|
115 |
sqlite3_blob_read $::blob [expr 500*1020-20] 20
|
sl@0
|
116 |
close $::blob
|
sl@0
|
117 |
}
|
sl@0
|
118 |
catch {db2 close}
|
sl@0
|
119 |
|
sl@0
|
120 |
do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
|
sl@0
|
121 |
PRAGMA auto_vacuum = 1;
|
sl@0
|
122 |
CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
|
sl@0
|
123 |
INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
|
sl@0
|
124 |
} -tclbody {
|
sl@0
|
125 |
# Read some data from the end of the large blob inserted into table
|
sl@0
|
126 |
# "blobs". This forces the IO error to occur while reading a pointer
|
sl@0
|
127 |
# map page for the purposes of seeking to the end of the blob.
|
sl@0
|
128 |
#
|
sl@0
|
129 |
sqlite3 db2 test.db
|
sl@0
|
130 |
set ::blob [db2 incrblob blobs v 1]
|
sl@0
|
131 |
sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321
|
sl@0
|
132 |
close $::blob
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
catch {db2 close}
|
sl@0
|
136 |
|
sl@0
|
137 |
finish_test
|