autovacuum_ioerr2.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # 2001 October 12
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing for correct handling of I/O errors
  13. # such as writes failing because the disk is full.
  14. #
  15. # The tests in this file use special facilities that are only
  16. # available in the SQLite test fixture.
  17. #
  18. # $Id: autovacuum_ioerr2.test,v 1.7 2008/07/12 14:52:20 drh Exp $
  19. set testdir [file dirname $argv0]
  20. source $testdir/tester.tcl
  21. # If this build of the library does not support auto-vacuum, omit this
  22. # whole file.
  23. ifcapable {!autovacuum} {
  24. finish_test
  25. return
  26. }
  27. do_ioerr_test autovacuum-ioerr2-1 -sqlprep {
  28. PRAGMA auto_vacuum = 1;
  29. CREATE TABLE abc(a);
  30. INSERT INTO abc VALUES(randstr(1500,1500));
  31. } -sqlbody {
  32. CREATE TABLE abc2(a);
  33. BEGIN;
  34. DELETE FROM abc;
  35. INSERT INTO abc VALUES(randstr(1500,1500));
  36. CREATE TABLE abc3(a);
  37. COMMIT;
  38. }
  39. do_ioerr_test autovacuum-ioerr2-2 -tclprep {
  40. execsql {
  41. PRAGMA auto_vacuum = 1;
  42. PRAGMA cache_size = 10;
  43. BEGIN;
  44. CREATE TABLE abc(a);
  45. INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow
  46. INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow
  47. }
  48. for {set i 0} {$i<150} {incr i} {
  49. execsql {
  50. INSERT INTO abc VALUES(randstr(100,100));
  51. }
  52. }
  53. execsql COMMIT
  54. } -sqlbody {
  55. BEGIN;
  56. DELETE FROM abc WHERE length(a)>100;
  57. UPDATE abc SET a = randstr(90,90);
  58. CREATE TABLE abc3(a);
  59. COMMIT;
  60. }
  61. do_ioerr_test autovacuum-ioerr2-3 -sqlprep {
  62. PRAGMA auto_vacuum = 1;
  63. CREATE TABLE abc(a);
  64. CREATE TABLE abc2(b);
  65. } -sqlbody {
  66. BEGIN;
  67. INSERT INTO abc2 VALUES(10);
  68. DROP TABLE abc;
  69. COMMIT;
  70. DROP TABLE abc2;
  71. }
  72. forcedelete backup.db
  73. ifcapable subquery {
  74. do_ioerr_test autovacuum-ioerr2-4 -tclprep {
  75. if {![file exists backup.db]} {
  76. sqlite3 dbb backup.db
  77. execsql {
  78. PRAGMA auto_vacuum = 1;
  79. BEGIN;
  80. CREATE TABLE abc(a);
  81. INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow
  82. INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow
  83. } dbb
  84. for {set i 0} {$i<2500} {incr i} {
  85. execsql {
  86. INSERT INTO abc VALUES(randstr(100,100));
  87. } dbb
  88. }
  89. execsql {
  90. COMMIT;
  91. PRAGMA cache_size = 10;
  92. } dbb
  93. dbb close
  94. }
  95. db close
  96. forcedelete test.db
  97. forcedelete test.db-journal
  98. forcecopy backup.db test.db
  99. set ::DB [sqlite3 db test.db]
  100. execsql {
  101. PRAGMA cache_size = 10;
  102. }
  103. } -sqlbody {
  104. BEGIN;
  105. DELETE FROM abc WHERE oid < 3;
  106. UPDATE abc SET a = randstr(100,100) WHERE oid > 2300;
  107. UPDATE abc SET a = randstr(1100,1100) WHERE oid =
  108. (select max(oid) from abc);
  109. COMMIT;
  110. }
  111. }
  112. do_ioerr_test autovacuum-ioerr2-1 -sqlprep {
  113. PRAGMA auto_vacuum = 1;
  114. CREATE TABLE abc(a);
  115. INSERT INTO abc VALUES(randstr(1500,1500));
  116. } -sqlbody {
  117. CREATE TABLE abc2(a);
  118. BEGIN;
  119. DELETE FROM abc;
  120. INSERT INTO abc VALUES(randstr(1500,1500));
  121. CREATE TABLE abc3(a);
  122. COMMIT;
  123. }
  124. finish_test