tkt35xx.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # 2008 November 20
  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.
  12. #
  13. # When a transaction rolls back, make sure that dirty pages in the
  14. # page cache which are not in the rollback journal are reinitialized
  15. # in the btree layer.
  16. #
  17. # $Id: tkt35xx.test,v 1.4 2009/06/05 17:09:12 drh Exp $
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. do_test tkt35xx-1.1 {
  21. execsql {
  22. PRAGMA auto_vacuum = 0;
  23. PRAGMA page_size = 1024;
  24. }
  25. } {}
  26. # Trigger the problem using explicit rollback.
  27. #
  28. do_test tkt35xx-1.1 {
  29. execsql {
  30. PRAGMA auto_vacuum = 0;
  31. CREATE TABLE t1(a,b,c);
  32. CREATE INDEX i1 ON t1(c);
  33. INSERT INTO t1 VALUES(0, 0, zeroblob(676));
  34. INSERT INTO t1 VALUES(1, 1, zeroblob(676));
  35. DELETE FROM t1;
  36. BEGIN;
  37. INSERT INTO t1 VALUES(0, 0, zeroblob(676));
  38. INSERT INTO t1 VALUES(1, 1, zeroblob(676));
  39. ROLLBACK;
  40. INSERT INTO t1 VALUES(0, 0, zeroblob(676));
  41. }
  42. execsql {
  43. INSERT INTO t1 VALUES(1, 1, zeroblob(676));
  44. }
  45. } {}
  46. # Trigger the problem using statement rollback.
  47. #
  48. db close
  49. delete_file test.db
  50. sqlite3 db test.db
  51. set big [string repeat abcdefghij 22] ;# 220 byte string
  52. do_test tkt35xx-1.2.1 {
  53. execsql {
  54. PRAGMA auto_vacuum = 0;
  55. PRAGMA page_size = 1024;
  56. CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
  57. INSERT INTO t3 VALUES(1, $big);
  58. INSERT INTO t3 VALUES(2, $big);
  59. INSERT INTO t3 VALUES(3, $big);
  60. INSERT INTO t3 VALUES(4, $big);
  61. CREATE TABLE t4(c, d);
  62. INSERT INTO t4 VALUES(5, $big);
  63. INSERT INTO t4 VALUES(1, $big);
  64. }
  65. } {}
  66. do_test tkt35xx-1.2.2 {
  67. catchsql {
  68. BEGIN;
  69. CREATE TABLE t5(e PRIMARY KEY, f);
  70. DROP TABLE t5;
  71. INSERT INTO t3(a, b) SELECT c, d FROM t4;
  72. }
  73. } {1 {PRIMARY KEY must be unique}}
  74. do_test tkt35xx-1.2.3 {
  75. # Show that the transaction has not been rolled back.
  76. catchsql BEGIN
  77. } {1 {cannot start a transaction within a transaction}}
  78. do_test tkt35xx-1.2.4 {
  79. execsql { SELECT count(*) FROM t3 }
  80. } {4}
  81. do_test tkt35xx-1.2.5 {
  82. # Before the bug was fixed, if SQLITE_DEBUG was defined an assert()
  83. # would fail during the following INSERT statement. If SQLITE_DEBUG
  84. # was not defined, then the statement would pass and the transaction
  85. # would be committed. But, the "SELECT count(*)" in tkt35xx-1.2.6 would
  86. # return 1, not 5. Data magically disappeared!
  87. #
  88. execsql {
  89. INSERT INTO t3 VALUES(5, $big);
  90. COMMIT;
  91. }
  92. } {}
  93. do_test tkt35xx-1.2.6 {
  94. execsql { SELECT count(*) FROM t3 }
  95. } {5}
  96. integrity_check tkt35xx-1.2.7
  97. finish_test