shared3.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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: shared3.test,v 1.4 2008/08/20 14:49:25 danielk1977 Exp $
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. set testprefix shared3
  16. db close
  17. ifcapable !shared_cache {
  18. finish_test
  19. return
  20. }
  21. set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
  22. # Ticket #1824
  23. #
  24. do_test shared3-1.1 {
  25. forcedelete test.db test.db-journal
  26. sqlite3 db1 test.db
  27. db1 eval {
  28. PRAGMA encoding=UTF16;
  29. CREATE TABLE t1(x,y);
  30. INSERT INTO t1 VALUES('abc','This is a test string');
  31. }
  32. db1 close
  33. sqlite3 db1 test.db
  34. db1 eval {SELECT * FROM t1}
  35. } {abc {This is a test string}}
  36. do_test shared3-1.2 {
  37. sqlite3 db2 test.db
  38. db2 eval {SELECT y FROM t1 WHERE x='abc'}
  39. } {{This is a test string}}
  40. db1 close
  41. db2 close
  42. do_test shared3-2.1 {
  43. sqlite3 db1 test.db
  44. execsql {
  45. PRAGMA main.cache_size = 10;
  46. } db1
  47. } {}
  48. do_test shared3-2.2 {
  49. execsql { PRAGMA main.cache_size } db1
  50. } {10}
  51. do_test shared3-2.3 {
  52. sqlite3 db2 test.db
  53. execsql { PRAGMA main.cache_size } db1
  54. } {10}
  55. do_test shared3-2.4 {
  56. execsql { PRAGMA main.cache_size } db2
  57. } {10}
  58. do_test shared3-2.5 {
  59. execsql { PRAGMA main.cache_size } db1
  60. } {10}
  61. # The cache-size should now be 10 pages. However at one point there was
  62. # a bug that caused the cache size to return to the default value when
  63. # a second connection was opened on the shared-cache (as happened in
  64. # test case shared3-2.3 above). The goal of the following tests is to
  65. # ensure that the cache-size really is 10 pages.
  66. #
  67. if {$::tcl_platform(platform)=="unix"} {
  68. set alternative_name ./test.db
  69. } else {
  70. set alternative_name TEST.DB
  71. }
  72. do_test shared3-2.6 {
  73. sqlite3 db3 $alternative_name
  74. catchsql {select count(*) from sqlite_master} db3
  75. } {0 1}
  76. do_test shared3-2.7 {
  77. execsql {
  78. BEGIN;
  79. INSERT INTO t1 VALUES(10, randomblob(5000))
  80. } db1
  81. catchsql {select count(*) from sqlite_master} db3
  82. } {0 1}
  83. do_test shared3-2.8 {
  84. db3 close
  85. execsql {
  86. INSERT INTO t1 VALUES(10, randomblob(10000))
  87. } db1
  88. # If the pager-cache is really still limited to 10 pages, then the INSERT
  89. # statement above should have caused the pager to grab an exclusive lock
  90. # on the database file so that the cache could be spilled.
  91. #
  92. catch { sqlite3 db3 $alternative_name }
  93. catchsql {select count(*) from sqlite_master} db3
  94. } {1 {database is locked}}
  95. db1 close
  96. db2 close
  97. db3 close
  98. #-------------------------------------------------------------------------
  99. # At one point this was causing a faulty assert to fail.
  100. #
  101. forcedelete test.db
  102. sqlite3 db test.db
  103. sqlite3 db2 test.db
  104. do_execsql_test 3.1 {
  105. PRAGMA auto_vacuum = 2;
  106. CREATE TABLE t1(x, y);
  107. INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
  108. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  109. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  110. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  111. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  112. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  113. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  114. INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
  115. }
  116. do_test 3.2 {
  117. execsql { SELECT count(*) FROM sqlite_master } db2
  118. } {1}
  119. do_execsql_test 3.3 {
  120. BEGIN;
  121. DELETE FROM t1 WHERE 1;
  122. PRAGMA incremental_vacuum;
  123. } {}
  124. do_test 3.4 {
  125. execsql { SELECT count(*) FROM sqlite_master } db2
  126. } {1}
  127. do_test 3.5 {
  128. execsql { COMMIT }
  129. } {}
  130. sqlite3_enable_shared_cache $::enable_shared_cache
  131. finish_test