1
0

shared2.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # 2005 January 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. #
  12. # $Id: shared2.test,v 1.8 2009/06/05 17:09:12 drh Exp $
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. source $testdir/lock_common.tcl
  16. source $testdir/malloc_common.tcl
  17. db close
  18. ifcapable !shared_cache {
  19. finish_test
  20. return
  21. }
  22. set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
  23. # Test that if we delete all rows from a table any read-uncommitted
  24. # cursors are correctly invalidated. Test on both table and index btrees.
  25. do_test shared2-1.1 {
  26. sqlite3 db1 test.db
  27. sqlite3 db2 test.db
  28. # Set up some data. Table "numbers" has 64 rows after this block
  29. # is executed.
  30. execsql {
  31. BEGIN;
  32. CREATE TABLE numbers(a PRIMARY KEY, b);
  33. INSERT INTO numbers(oid) VALUES(NULL);
  34. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  35. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  36. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  37. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  38. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  39. INSERT INTO numbers(oid) SELECT NULL FROM numbers;
  40. UPDATE numbers set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789';
  41. COMMIT;
  42. } db1
  43. } {}
  44. do_test shared2-1.2 {
  45. # Put connection 2 in read-uncommitted mode and start a SELECT on table
  46. # 'numbers'. Half way through the SELECT, use connection 1 to delete the
  47. # contents of this table.
  48. execsql {
  49. pragma read_uncommitted = 1;
  50. } db2
  51. set count [execsql {SELECT count(*) FROM numbers} db2]
  52. db2 eval {SELECT a FROM numbers ORDER BY oid} {
  53. if {$a==32} {
  54. execsql {
  55. BEGIN;
  56. DELETE FROM numbers;
  57. } db1
  58. }
  59. }
  60. list $a $count
  61. } {32 64}
  62. do_test shared2-1.3 {
  63. # Same test as 1.2, except scan using the index this time.
  64. execsql {
  65. ROLLBACK;
  66. } db1
  67. set count [execsql {SELECT count(*) FROM numbers} db2]
  68. db2 eval {SELECT a, b FROM numbers ORDER BY a} {
  69. if {$a==32} {
  70. execsql {
  71. DELETE FROM numbers;
  72. } db1
  73. }
  74. }
  75. list $a $count
  76. } {32 64}
  77. db1 close
  78. db2 close
  79. do_test shared2-3.2 {
  80. sqlite3_enable_shared_cache 1
  81. } {1}
  82. forcedelete test.db
  83. sqlite3 db test.db
  84. do_test shared2-4.1 {
  85. execsql {
  86. CREATE TABLE t0(a, b);
  87. CREATE TABLE t1(a, b DEFAULT 'hello world');
  88. }
  89. } {}
  90. db close
  91. sqlite3 db test.db
  92. sqlite3 db2 test.db
  93. do_test shared2-4.2 {
  94. execsql { SELECT a, b FROM t0 } db
  95. execsql { INSERT INTO t1(a) VALUES(1) } db2
  96. } {}
  97. do_test shared2-4.3 {
  98. db2 close
  99. db close
  100. } {}
  101. # At one point, this was causing a crash.
  102. #
  103. do_test shared2-5.1 {
  104. sqlite3 db test.db
  105. sqlite3 db2 test.db
  106. execsql { CREATE TABLE t2(a, b, c) }
  107. # The following statement would crash when attempting to sqlite3_free()
  108. # a pointer allocated from a lookaside buffer.
  109. execsql { CREATE INDEX i1 ON t2(a) } db2
  110. } {}
  111. db close
  112. db2 close
  113. # The following test verifies that shared-cache mode does not automatically
  114. # turn on exclusive-locking mode for some reason.
  115. do_multiclient_test {tn} {
  116. sql1 { CREATE TABLE t1(a, b) }
  117. sql2 { CREATE TABLE t2(a, b) }
  118. do_test shared2-6.$tn.1 { sql1 { SELECT * FROM t2 } } {}
  119. do_test shared2-6.$tn.2 { sql2 { SELECT * FROM t1 } } {}
  120. }
  121. sqlite3_enable_shared_cache $::enable_shared_cache
  122. finish_test