incrblob_err.test 3.6 KB

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