savepoint3.test 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # 2008 December 15
  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: savepoint3.test,v 1.5 2009/06/05 17:09:12 drh Exp $
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. source $testdir/malloc_common.tcl
  16. do_malloc_test savepoint3-1 -sqlprep {
  17. CREATE TABLE t1(a, b, c);
  18. INSERT INTO t1 VALUES(1, 2, 3);
  19. } -sqlbody {
  20. SAVEPOINT one;
  21. INSERT INTO t1 VALUES(4, 5, 6);
  22. SAVEPOINT two;
  23. DELETE FROM t1;
  24. ROLLBACK TO two;
  25. RELEASE one;
  26. }
  27. do_malloc_test savepoint3-2 -sqlprep {
  28. PRAGMA cache_size = 10;
  29. CREATE TABLE t1(a, b, c);
  30. INSERT INTO t1 VALUES(randstr(400,400), randstr(400,400), randstr(400,400));
  31. INSERT INTO t1 SELECT
  32. randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  33. INSERT INTO t1
  34. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  35. INSERT INTO t1
  36. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  37. INSERT INTO t1
  38. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  39. INSERT INTO t1
  40. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  41. INSERT INTO t1
  42. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  43. INSERT INTO t1
  44. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  45. INSERT INTO t1
  46. SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;
  47. } -sqlbody {
  48. PRAGMA cache_size = 10;
  49. SAVEPOINT one;
  50. DELETE FROM t1 WHERE rowid < 5;
  51. SAVEPOINT two;
  52. DELETE FROM t1 WHERE rowid > 10;
  53. ROLLBACK TO two;
  54. ROLLBACK TO one;
  55. RELEASE one;
  56. }
  57. do_ioerr_test savepoint3.3 -sqlprep {
  58. CREATE TABLE t1(a, b, c);
  59. INSERT INTO t1 VALUES(1, randstr(1000,1000), randstr(1000,1000));
  60. INSERT INTO t1 VALUES(2, randstr(1000,1000), randstr(1000,1000));
  61. } -sqlbody {
  62. BEGIN;
  63. UPDATE t1 SET a = 3 WHERE a = 1;
  64. SAVEPOINT one;
  65. UPDATE t1 SET a = 4 WHERE a = 2;
  66. COMMIT;
  67. } -cleanup {
  68. db eval {
  69. SAVEPOINT one;
  70. RELEASE one;
  71. }
  72. }
  73. # The following test does a really big savepoint rollback. One involving
  74. # more than 4000 pages. The idea is to get a specific sqlite3BitvecSet()
  75. # operation in pagerPlaybackSavepoint() to fail.
  76. #do_malloc_test savepoint3-4 -sqlprep {
  77. # BEGIN;
  78. # CREATE TABLE t1(a, b);
  79. # CREATE INDEX i1 ON t1(a);
  80. # CREATE INDEX i2 ON t1(b);
  81. # INSERT INTO t1 VALUES(randstr(500,500), randstr(500,500)); -- 1
  82. # INSERT INTO t1 VALUES(randstr(500,500), randstr(500,500)); -- 2
  83. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 4
  84. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 8
  85. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 16
  86. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 32
  87. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 64
  88. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 128
  89. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 256
  90. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 512
  91. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 1024
  92. # INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; -- 2048
  93. # COMMIT;
  94. # BEGIN;
  95. # SAVEPOINT abc;
  96. # UPDATE t1 SET a = randstr(500,500);
  97. #} -sqlbody {
  98. # ROLLBACK TO abc;
  99. #}
  100. # Cause a specific malloc in savepoint rollback code to fail.
  101. #
  102. do_malloc_test savepoint3-4 -start 7 -sqlprep {
  103. PRAGMA auto_vacuum = incremental;
  104. PRAGMA cache_size = 1000;
  105. CREATE TABLE t1(a, b);
  106. CREATE TABLE t2(a, b);
  107. CREATE TABLE t3(a, b);
  108. INSERT INTO t1 VALUES(1, randstr(500,500));
  109. INSERT INTO t1 VALUES(2, randstr(500,500));
  110. INSERT INTO t1 VALUES(3, randstr(500,500));
  111. DELETE FROM t1;
  112. BEGIN;
  113. INSERT INTO t1 VALUES(1, randstr(500,500));
  114. INSERT INTO t1 VALUES(2, randstr(500,500));
  115. INSERT INTO t1 VALUES(3, randstr(500,500));
  116. DROP TABLE t3; -- Page 5 of the database file is now free.
  117. DROP TABLE t2; -- Page 4 of the database file is now free.
  118. SAVEPOINT abc;
  119. PRAGMA incremental_vacuum;
  120. } -sqlbody {
  121. ROLLBACK TO abc;
  122. }
  123. finish_test