| OLD | NEW |
| 1 # 2007 May 1 | 1 # 2007 May 1 |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 db close | 122 db close |
| 123 forcedelete test.db test.db-journal | 123 forcedelete test.db test.db-journal |
| 124 | 124 |
| 125 sqlite3 db test.db | 125 sqlite3 db test.db |
| 126 execsql "PRAGMA mmap_size = 0" | 126 execsql "PRAGMA mmap_size = 0" |
| 127 execsql "PRAGMA auto_vacuum = $AutoVacuumMode" | 127 execsql "PRAGMA auto_vacuum = $AutoVacuumMode" |
| 128 | 128 |
| 129 # Extra value added to size answers |
| 130 set ib2_extra 0 |
| 131 if {$AutoVacuumMode} {incr ib2_extra} |
| 132 if {[nonzero_reserved_bytes]} {incr ib2_extra} |
| 133 |
| 129 do_test incrblob-2.$AutoVacuumMode.1 { | 134 do_test incrblob-2.$AutoVacuumMode.1 { |
| 130 set ::str [string repeat abcdefghij 2900] | 135 set ::str [string repeat abcdefghij 2900] |
| 131 execsql { | 136 execsql { |
| 132 BEGIN; | 137 BEGIN; |
| 133 CREATE TABLE blobs(k PRIMARY KEY, v BLOB, i INTEGER); | 138 CREATE TABLE blobs(k PRIMARY KEY, v BLOB, i INTEGER); |
| 134 DELETE FROM blobs; | 139 DELETE FROM blobs; |
| 135 INSERT INTO blobs VALUES('one', $::str || randstr(500,500), 45); | 140 INSERT INTO blobs VALUES('one', $::str || randstr(500,500), 45); |
| 136 COMMIT; | 141 COMMIT; |
| 137 } | 142 } |
| 138 expr [file size test.db]/1024 | 143 expr [file size test.db]/1024 |
| 139 } [expr 31 + $AutoVacuumMode] | 144 } [expr 31 + $ib2_extra] |
| 140 | 145 |
| 141 ifcapable autovacuum { | 146 ifcapable autovacuum { |
| 142 do_test incrblob-2.$AutoVacuumMode.2 { | 147 do_test incrblob-2.$AutoVacuumMode.2 { |
| 143 execsql { | 148 execsql { |
| 144 PRAGMA auto_vacuum; | 149 PRAGMA auto_vacuum; |
| 145 } | 150 } |
| 146 } $AutoVacuumMode | 151 } $AutoVacuumMode |
| 147 } | 152 } |
| 148 | 153 |
| 149 do_test incrblob-2.$AutoVacuumMode.3 { | 154 do_test incrblob-2.$AutoVacuumMode.3 { |
| 150 # Open and close the db to make sure the page cache is empty. | 155 # Open and close the db to make sure the page cache is empty. |
| 151 db close | 156 db close |
| 152 sqlite3 db test.db | 157 sqlite3 db test.db |
| 153 execsql "PRAGMA mmap_size = 0" | 158 execsql "PRAGMA mmap_size = 0" |
| 154 | 159 |
| 155 # Read the last 20 bytes of the blob via a blob handle. | 160 # Read the last 20 bytes of the blob via a blob handle. |
| 156 set ::blob [db incrblob blobs v 1] | 161 set ::blob [db incrblob blobs v 1] |
| 157 seek $::blob -20 end | 162 seek $::blob -20 end |
| 158 set ::fragment [read $::blob] | 163 set ::fragment [read $::blob] |
| 159 close $::blob | 164 close $::blob |
| 160 | 165 |
| 161 # If the database is not in auto-vacuum mode, the whole of | 166 # If the database is not in auto-vacuum mode, the whole of |
| 162 # the overflow-chain must be scanned. In auto-vacuum mode, | 167 # the overflow-chain must be scanned. In auto-vacuum mode, |
| 163 # sqlite uses the ptrmap pages to avoid reading the other pages. | 168 # sqlite uses the ptrmap pages to avoid reading the other pages. |
| 164 # | 169 # |
| 165 nRead db | 170 nRead db |
| 166 } [expr $AutoVacuumMode ? 4 : 30] | 171 } [expr $AutoVacuumMode ? 4 : 30+$ib2_extra] |
| 167 | 172 |
| 168 do_test incrblob-2.$AutoVacuumMode.4 { | 173 do_test incrblob-2.$AutoVacuumMode.4 { |
| 169 string range [db one {SELECT v FROM blobs}] end-19 end | 174 string range [db one {SELECT v FROM blobs}] end-19 end |
| 170 } $::fragment | 175 } $::fragment |
| 171 | 176 |
| 172 do_test incrblob-2.$AutoVacuumMode.5 { | 177 do_test incrblob-2.$AutoVacuumMode.5 { |
| 173 # Open and close the db to make sure the page cache is empty. | 178 # Open and close the db to make sure the page cache is empty. |
| 174 db close | 179 db close |
| 175 sqlite3 db test.db | 180 sqlite3 db test.db |
| 176 execsql "PRAGMA mmap_size = 0" | 181 execsql "PRAGMA mmap_size = 0" |
| 177 | 182 |
| 178 # Write the second-to-last 20 bytes of the blob via a blob handle. | 183 # Write the second-to-last 20 bytes of the blob via a blob handle. |
| 179 # | 184 # |
| 180 set ::blob [db incrblob blobs v 1] | 185 set ::blob [db incrblob blobs v 1] |
| 181 seek $::blob -40 end | 186 seek $::blob -40 end |
| 182 puts -nonewline $::blob "1234567890abcdefghij" | 187 puts -nonewline $::blob "1234567890abcdefghij" |
| 183 flush $::blob | 188 flush $::blob |
| 184 | 189 |
| 185 # If the database is not in auto-vacuum mode, the whole of | 190 # If the database is not in auto-vacuum mode, the whole of |
| 186 # the overflow-chain must be scanned. In auto-vacuum mode, | 191 # the overflow-chain must be scanned. In auto-vacuum mode, |
| 187 # sqlite uses the ptrmap pages to avoid reading the other pages. | 192 # sqlite uses the ptrmap pages to avoid reading the other pages. |
| 188 # | 193 # |
| 189 nRead db | 194 nRead db |
| 190 } [expr $AutoVacuumMode ? 4 : 30] | 195 } [expr $AutoVacuumMode ? 4 : 30 + $ib2_extra] |
| 191 | 196 |
| 192 # Pages 1 (the write-counter) and 32 (the blob data) were written. | 197 # Pages 1 (the write-counter) and 32 (the blob data) were written. |
| 193 do_test incrblob-2.$AutoVacuumMode.6 { | 198 do_test incrblob-2.$AutoVacuumMode.6 { |
| 194 close $::blob | 199 close $::blob |
| 195 nWrite db | 200 nWrite db |
| 196 } 2 | 201 } 2 |
| 197 | 202 |
| 198 do_test incrblob-2.$AutoVacuumMode.7 { | 203 do_test incrblob-2.$AutoVacuumMode.7 { |
| 199 string range [db one {SELECT v FROM blobs}] end-39 end-20 | 204 string range [db one {SELECT v FROM blobs}] end-39 end-20 |
| 200 } "1234567890abcdefghij" | 205 } "1234567890abcdefghij" |
| 201 | 206 |
| 202 do_test incrblob-2.$AutoVacuumMode.8 { | 207 do_test incrblob-2.$AutoVacuumMode.8 { |
| 203 # Open and close the db to make sure the page cache is empty. | 208 # Open and close the db to make sure the page cache is empty. |
| 204 db close | 209 db close |
| 205 sqlite3 db test.db | 210 sqlite3 db test.db |
| 206 execsql { PRAGMA mmap_size = 0 } | 211 execsql { PRAGMA mmap_size = 0 } |
| 207 | 212 |
| 208 execsql { SELECT i FROM blobs } | 213 execsql { SELECT i FROM blobs } |
| 209 } {45} | 214 } {45} |
| 210 | 215 |
| 211 do_test incrblob-2.$AutoVacuumMode.9 { | 216 do_test incrblob-2.$AutoVacuumMode.9 { |
| 212 nRead db | 217 nRead db |
| 213 } [expr $AutoVacuumMode ? 4 : 30] | 218 } [expr $AutoVacuumMode ? 4 : 30 + $ib2_extra] |
| 214 } | 219 } |
| 215 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) | 220 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) |
| 216 | 221 |
| 217 #------------------------------------------------------------------------ | 222 #------------------------------------------------------------------------ |
| 218 # incrblob-3.*: | 223 # incrblob-3.*: |
| 219 # | 224 # |
| 220 # Test the outcome of trying to write to a read-only blob handle. | 225 # Test the outcome of trying to write to a read-only blob handle. |
| 221 # | 226 # |
| 222 do_test incrblob-3.1 { | 227 do_test incrblob-3.1 { |
| 223 set ::blob [db incrblob -readonly blobs v 1] | 228 set ::blob [db incrblob -readonly blobs v 1] |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 382 |
| 378 | 383 |
| 379 #------------------------------------------------------------------------ | 384 #------------------------------------------------------------------------ |
| 380 # incrblob-5.*: | 385 # incrblob-5.*: |
| 381 # | 386 # |
| 382 # Test that opening a blob in an attached database works. | 387 # Test that opening a blob in an attached database works. |
| 383 # | 388 # |
| 384 ifcapable attach { | 389 ifcapable attach { |
| 385 do_test incrblob-5.1 { | 390 do_test incrblob-5.1 { |
| 386 forcedelete test2.db test2.db-journal | 391 forcedelete test2.db test2.db-journal |
| 387 set ::size [expr [file size [info script]]] | 392 set ::size [expr [file size $::cmdlinearg(INFO_SCRIPT)]] |
| 388 execsql { | 393 execsql { |
| 389 ATTACH 'test2.db' AS aux; | 394 ATTACH 'test2.db' AS aux; |
| 390 CREATE TABLE aux.files(name, text); | 395 CREATE TABLE aux.files(name, text); |
| 391 INSERT INTO aux.files VALUES('this one', zeroblob($::size)); | 396 INSERT INTO aux.files VALUES('this one', zeroblob($::size)); |
| 392 } | 397 } |
| 393 set fd [db incrblob aux files text 1] | 398 set fd [db incrblob aux files text 1] |
| 394 fconfigure $fd -translation binary | 399 fconfigure $fd -translation binary |
| 395 set fd2 [open [info script]] | 400 set fd2 [open $::cmdlinearg(INFO_SCRIPT)] |
| 396 fconfigure $fd2 -translation binary | 401 fconfigure $fd2 -translation binary |
| 397 puts -nonewline $fd [read $fd2] | 402 puts -nonewline $fd [read $fd2] |
| 398 close $fd | 403 close $fd |
| 399 close $fd2 | 404 close $fd2 |
| 400 set ::text [db one {select text from aux.files}] | 405 set ::text [db one {select text from aux.files}] |
| 401 string length $::text | 406 string length $::text |
| 402 } [file size [info script]] | 407 } [file size $::cmdlinearg(INFO_SCRIPT)] |
| 403 do_test incrblob-5.2 { | 408 do_test incrblob-5.2 { |
| 404 set fd2 [open [info script]] | 409 set fd2 [open $::cmdlinearg(INFO_SCRIPT)] |
| 405 fconfigure $fd2 -translation binary | 410 fconfigure $fd2 -translation binary |
| 406 set ::data [read $fd2] | 411 set ::data [read $fd2] |
| 407 close $fd2 | 412 close $fd2 |
| 408 set ::data | 413 set ::data |
| 409 } $::text | 414 } $::text |
| 410 } | 415 } |
| 411 | 416 |
| 412 # free memory | 417 # free memory |
| 413 unset -nocomplain ::data | 418 unset -nocomplain ::data |
| 414 unset -nocomplain ::text | 419 unset -nocomplain ::text |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 list $rc $msg | 574 list $rc $msg |
| 570 } {0 {}} | 575 } {0 {}} |
| 571 do_test incrblob-7.1.$tn.6 { | 576 do_test incrblob-7.1.$tn.6 { |
| 572 execsql { | 577 execsql { |
| 573 SELECT d FROM t1; | 578 SELECT d FROM t1; |
| 574 } | 579 } |
| 575 } {15} | 580 } {15} |
| 576 | 581 |
| 577 } | 582 } |
| 578 | 583 |
| 579 set fd [open [info script]] | 584 set fd [open $::cmdlinearg(INFO_SCRIPT)] |
| 580 fconfigure $fd -translation binary | 585 fconfigure $fd -translation binary |
| 581 set ::data [read $fd 14000] | 586 set ::data [read $fd 14000] |
| 582 close $fd | 587 close $fd |
| 583 | 588 |
| 584 db close | 589 db close |
| 585 forcedelete test.db test.db-journal | 590 forcedelete test.db test.db-journal |
| 586 sqlite3 db test.db | 591 sqlite3 db test.db |
| 587 | 592 |
| 588 do_test incrblob-7.2.1 { | 593 do_test incrblob-7.2.1 { |
| 589 execsql { | 594 execsql { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 # an error message was set using a call similar to sqlite3_mprintf(zErr), | 684 # an error message was set using a call similar to sqlite3_mprintf(zErr), |
| 680 # where zErr is an arbitrary string. This is no good if the string contains | 685 # where zErr is an arbitrary string. This is no good if the string contains |
| 681 # characters that can be mistaken for printf() formatting directives. | 686 # characters that can be mistaken for printf() formatting directives. |
| 682 # | 687 # |
| 683 do_test incrblob-9.1 { | 688 do_test incrblob-9.1 { |
| 684 list [catch { db incrblob t1 "A tricky column name %s%s" 1 } msg] $msg | 689 list [catch { db incrblob t1 "A tricky column name %s%s" 1 } msg] $msg |
| 685 } {1 {no such column: "A tricky column name %s%s"}} | 690 } {1 {no such column: "A tricky column name %s%s"}} |
| 686 | 691 |
| 687 | 692 |
| 688 finish_test | 693 finish_test |
| OLD | NEW |