tkt-2d1a5c67d.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # 2011 May 19
  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. Specifically,
  12. # it tests that ticket [2d1a5c67dfc2363e44f29d9bbd57f7331851390a] has
  13. # been resolved.
  14. #
  15. #
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. set testprefix tkt-2d1a5c67d
  20. ifcapable {!wal || !vtab} {finish_test; return}
  21. for {set ii 1} {$ii<=10} {incr ii} {
  22. do_test tkt-2d1a5c67d.1.$ii {
  23. db close
  24. forcedelete test.db test.db-wal
  25. sqlite3 db test.db
  26. db eval "PRAGMA cache_size=$::ii"
  27. db eval {
  28. PRAGMA journal_mode=WAL;
  29. CREATE TABLE t1(a,b);
  30. CREATE INDEX t1b ON t1(b);
  31. CREATE TABLE t2(x,y UNIQUE);
  32. INSERT INTO t2 VALUES(3,4);
  33. BEGIN;
  34. INSERT INTO t1(a,b) VALUES(1,2);
  35. SELECT 'A', * FROM t2 WHERE y=4;
  36. SELECT 'B', * FROM t1;
  37. COMMIT;
  38. SELECT 'C', * FROM t1;
  39. }
  40. } {wal A 3 4 B 1 2 C 1 2}
  41. }
  42. db close
  43. forcedelete test.db test.db-wal
  44. sqlite3 db test.db
  45. load_static_extension db wholenumber
  46. db eval {
  47. PRAGMA journal_mode=WAL;
  48. CREATE TABLE t1(a,b);
  49. CREATE INDEX t1b ON t1(b);
  50. CREATE TABLE t2(x,y);
  51. CREATE VIRTUAL TABLE nums USING wholenumber;
  52. INSERT INTO t2 SELECT value, randomblob(1000) FROM nums
  53. WHERE value BETWEEN 1 AND 1000;
  54. }
  55. for {set ii 1} {$ii<=10} {incr ii} {
  56. do_test tkt-2d1a5c67d.2.$ii {
  57. db eval "PRAGMA cache_size=$::ii"
  58. db eval {
  59. DELETE FROM t1;
  60. BEGIN;
  61. INSERT INTO t1(a,b) VALUES(1,2);
  62. SELECT sum(length(y)) FROM t2;
  63. COMMIT;
  64. SELECT * FROM t1;
  65. }
  66. } {1000000 1 2}
  67. }
  68. db close
  69. sqlite3 db test.db
  70. do_execsql_test 3.1 {
  71. PRAGMA cache_size = 10;
  72. CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
  73. CREATE TABLE t4(a);
  74. }
  75. do_execsql_test 3.2 {
  76. INSERT INTO t3 VALUES(NULL, randomblob(500));
  77. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 2
  78. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 4
  79. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 8
  80. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 16
  81. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 32
  82. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 64
  83. INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 128
  84. }
  85. do_execsql_test 3.3 {
  86. BEGIN;
  87. INSERT INTO t4 VALUES('xyz');
  88. }
  89. do_test 3.4 {
  90. set blobs [list]
  91. for {set i 1} {$i<100} {incr i} {
  92. set b [db incrblob -readonly t3 b $i]
  93. read $b
  94. lappend blobs $b
  95. }
  96. execsql COMMIT
  97. execsql { SELECT * FROM t4 WHERE a = 'xyz' }
  98. } {xyz}
  99. do_test 3.5 {
  100. foreach b $blobs { close $b }
  101. execsql { SELECT * FROM t4 WHERE a = 'xyz' }
  102. } {xyz}
  103. # Check that recovery works on the WAL file.
  104. #
  105. forcedelete test.db2-wal test.db2
  106. do_test 3.6 {
  107. copy_file test.db-wal test.db2-wal
  108. copy_file test.db test.db2
  109. sqlite3 db2 test.db2
  110. execsql { SELECT * FROM t4 WHERE a = 'xyz' } db2
  111. } {xyz}
  112. finish_test