OLD | NEW |
1 # 2015 December 10 | 1 # 2015 December 10 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 INSERT INTO t1 VALUES(4, randomblob(500), randomblob(500)); | 139 INSERT INTO t1 VALUES(4, randomblob(500), randomblob(500)); |
140 INSERT INTO t1 VALUES(5, randomblob(500), randomblob(500)); | 140 INSERT INTO t1 VALUES(5, randomblob(500), randomblob(500)); |
141 INSERT INTO t1 VALUES(6, randomblob(500), randomblob(500)); | 141 INSERT INTO t1 VALUES(6, randomblob(500), randomblob(500)); |
142 BEGIN; | 142 BEGIN; |
143 } | 143 } |
144 } -body { | 144 } -body { |
145 if { [catch { sqlite3_snapshot_open db main $::snapshot } msg] } { | 145 if { [catch { sqlite3_snapshot_open db main $::snapshot } msg] } { |
146 error $msg | 146 error $msg |
147 } | 147 } |
148 } -test { | 148 } -test { |
149 faultsim_test_result {0 {}} {1 SQLITE_IOERR} \ | 149 faultsim_test_result {0 {}} {1 SQLITE_IOERR} {1 SQLITE_NOMEM} \ |
150 {1 SQLITE_IOERR_NOMEM} {1 SQLITE_IOERR_READ} | 150 {1 SQLITE_IOERR_NOMEM} {1 SQLITE_IOERR_READ} |
151 if {$testrc==0} { | 151 if {$testrc==0} { |
152 set res [db eval { | 152 set res [db eval { |
153 SELECT a FROM t1; | 153 SELECT a FROM t1; |
154 PRAGMA integrity_check; | 154 PRAGMA integrity_check; |
155 }] | 155 }] |
156 if {$res != "1 2 3 ok"} { error "res is $res" } | 156 if {$res != "1 2 3 ok"} { error "res is $res" } |
157 } | 157 } |
158 | 158 |
159 sqlite3_snapshot_free $::snapshot | 159 sqlite3_snapshot_free $::snapshot |
160 } | 160 } |
161 | 161 |
| 162 #------------------------------------------------------------------------- |
| 163 # Test the handling of faults that occur within sqlite3_snapshot_recover(). |
| 164 # |
| 165 reset_db |
| 166 do_execsql_test 4.0 { |
| 167 PRAGMA journal_mode = wal; |
| 168 CREATE TABLE t1(zzz); |
| 169 INSERT INTO t1 VALUES('abc'); |
| 170 INSERT INTO t1 VALUES('def'); |
| 171 } {wal} |
| 172 faultsim_save_and_close |
| 173 |
| 174 do_test 4.0.1 { |
| 175 faultsim_restore_and_reopen |
| 176 db eval { SELECT * FROM sqlite_master } |
| 177 sqlite3_snapshot_recover db main |
| 178 } {} |
| 179 db close |
| 180 |
| 181 do_faultsim_test 4.0 -faults oom* -prep { |
| 182 faultsim_restore_and_reopen |
| 183 db eval { SELECT * FROM sqlite_master } |
| 184 } -body { |
| 185 sqlite3_snapshot_recover db main |
| 186 } -test { |
| 187 faultsim_test_result {0 {}} {1 SQLITE_NOMEM} {1 SQLITE_IOERR_NOMEM} |
| 188 } |
| 189 |
| 190 # The following test cases contrive to call sqlite3_snapshot_recover() |
| 191 # before all pages of the *-shm file have been mapped. This tests an |
| 192 # extra branch of error handling logic in snapshot_recover(). |
| 193 # |
| 194 reset_db |
| 195 do_execsql_test 4.1.0 { |
| 196 PRAGMA page_size = 512; |
| 197 PRAGMA journal_mode = wal; |
| 198 PRAGMA wal_autocheckpoint = 0; |
| 199 CREATE TABLE t1(zzz); |
| 200 INSERT INTO t1 VALUES(randomblob( 500 * 9500 )); |
| 201 PRAGMA user_version = 211; |
| 202 } {wal 0} |
| 203 |
| 204 do_test 4.1.1 { |
| 205 list [file size test.db-shm] [file size test.db] |
| 206 } {98304 512} |
| 207 |
| 208 faultsim_save_and_close |
| 209 do_faultsim_test 4.1 -faults shm* -prep { |
| 210 catch { db2 close } |
| 211 catch { db close } |
| 212 faultsim_restore_and_reopen |
| 213 sqlite3 db2 test.db |
| 214 db2 eval { SELECT * FROM sqlite_master } |
| 215 db eval BEGIN |
| 216 sqlite3_snapshot_get_blob db main |
| 217 db eval COMMIT |
| 218 } -body { |
| 219 sqlite3_snapshot_recover db main |
| 220 } -test { |
| 221 faultsim_test_result {0 {}} {1 SQLITE_IOERR} |
| 222 } |
| 223 |
162 | 224 |
163 | 225 |
164 finish_test | 226 finish_test |
OLD | NEW |