Start of experimental implementation of SQL window functions. Does not yet
[sqlite.git] / test / incrblob_err.test
blob0db8b0dcba6bba8b23a99f19764846cea01308e7
1 # 2007 May 1
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
17 set ::testprefix incrblob_err
19 ifcapable {!incrblob  || !memdebug || !tclvar} {
20   finish_test
21   return
24 source $testdir/malloc_common.tcl
26 unset -nocomplain ::fd ::data
27 set ::fd [open $::cmdlinearg(INFO_SCRIPT)]
28 set ::data [read $::fd]
29 close $::fd
31 do_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
44 do_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   }
59 do_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   }
78 do_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
86 do_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
96 do_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
107 do_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
121 catch {db2 close}
123 do_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
138 catch {db2 close}
140 finish_test