1
0

pragma2.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # 2002 March 6
  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. # This file implements tests for the PRAGMA command.
  14. #
  15. # $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Test organization:
  19. #
  20. # pragma2-1.*: Test freelist_count pragma on the main database.
  21. # pragma2-2.*: Test freelist_count pragma on an attached database.
  22. # pragma2-3.*: Test trying to write to the freelist_count is a no-op.
  23. # pragma2-4.*: Tests for PRAGMA cache_spill
  24. #
  25. ifcapable !pragma||!schema_pragmas {
  26. finish_test
  27. return
  28. }
  29. # Delete the preexisting database to avoid the special setup
  30. # that the "all.test" script does.
  31. #
  32. db close
  33. delete_file test.db test.db-journal
  34. delete_file test3.db test3.db-journal
  35. sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
  36. db eval {PRAGMA auto_vacuum=0}
  37. do_test pragma2-1.1 {
  38. execsql {
  39. PRAGMA freelist_count;
  40. }
  41. } {0}
  42. do_test pragma2-1.2 {
  43. execsql {
  44. CREATE TABLE abc(a, b, c);
  45. PRAGMA freelist_count;
  46. }
  47. } {0}
  48. do_test pragma2-1.3 {
  49. execsql {
  50. DROP TABLE abc;
  51. PRAGMA freelist_count;
  52. }
  53. } {1}
  54. do_test pragma2-1.4 {
  55. execsql {
  56. PRAGMA main.freelist_count;
  57. }
  58. } {1}
  59. forcedelete test2.db
  60. forcedelete test2.db-journal
  61. ifcapable attach {
  62. do_test pragma2-2.1 {
  63. execsql {
  64. ATTACH 'test2.db' AS aux;
  65. PRAGMA aux.auto_vacuum=OFF;
  66. PRAGMA aux.freelist_count;
  67. }
  68. } {0}
  69. do_test pragma2-2.2 {
  70. execsql {
  71. CREATE TABLE aux.abc(a, b, c);
  72. PRAGMA aux.freelist_count;
  73. }
  74. } {0}
  75. do_test pragma2-2.3 {
  76. set ::val [string repeat 0123456789 1000]
  77. execsql {
  78. INSERT INTO aux.abc VALUES(1, 2, $::val);
  79. PRAGMA aux.freelist_count;
  80. }
  81. } {0}
  82. do_test pragma2-2.4 {
  83. expr {[file size test2.db] / 1024}
  84. } {11}
  85. do_test pragma2-2.5 {
  86. execsql {
  87. DELETE FROM aux.abc;
  88. PRAGMA aux.freelist_count;
  89. }
  90. } {9}
  91. do_test pragma2-3.1 {
  92. execsql {
  93. PRAGMA aux.freelist_count;
  94. PRAGMA main.freelist_count;
  95. PRAGMA freelist_count;
  96. }
  97. } {9 1 1}
  98. do_test pragma2-3.2 {
  99. execsql {
  100. PRAGMA freelist_count = 500;
  101. PRAGMA freelist_count;
  102. }
  103. } {1 1}
  104. do_test pragma2-3.3 {
  105. execsql {
  106. PRAGMA aux.freelist_count = 500;
  107. PRAGMA aux.freelist_count;
  108. }
  109. } {9 9}
  110. }
  111. # Default setting of PRAGMA cache_spill is always ON
  112. #
  113. # EVIDENCE-OF: R-51036-62828 PRAGMA cache_spill; PRAGMA
  114. # cache_spill=boolean;
  115. #
  116. # EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default
  117. #
  118. db close
  119. delete_file test.db test.db-journal
  120. delete_file test2.db test2.db-journal
  121. sqlite3 db test.db
  122. do_execsql_test pragma2-4.1 {
  123. PRAGMA cache_spill;
  124. PRAGMA main.cache_spill;
  125. PRAGMA temp.cache_spill;
  126. } {1 1 1}
  127. do_execsql_test pragma2-4.2 {
  128. PRAGMA cache_spill=OFF;
  129. PRAGMA cache_spill;
  130. PRAGMA main.cache_spill;
  131. PRAGMA temp.cache_spill;
  132. } {0 0 0}
  133. do_execsql_test pragma2-4.3 {
  134. PRAGMA page_size=1024;
  135. PRAGMA cache_size=50;
  136. BEGIN;
  137. CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
  138. INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400));
  139. INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1;
  140. INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1;
  141. INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1;
  142. INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1;
  143. INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1;
  144. INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1;
  145. INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1;
  146. COMMIT;
  147. ATTACH 'test2.db' AS aux1;
  148. CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d);
  149. INSERT INTO t2 SELECT * FROM t1;
  150. DETACH aux1;
  151. PRAGMA cache_spill=ON;
  152. } {}
  153. sqlite3_release_memory
  154. #
  155. # EVIDENCE-OF: R-07634-40532 The cache_spill pragma enables or disables
  156. # the ability of the pager to spill dirty cache pages to the database
  157. # file in the middle of a transaction.
  158. #
  159. do_test pragma2-4.4 {
  160. db eval {
  161. BEGIN;
  162. UPDATE t1 SET c=c+1;
  163. PRAGMA lock_status;
  164. }
  165. } {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill
  166. do_test pragma2-4.5 {
  167. db eval {
  168. COMMIT;
  169. PRAGMA cache_spill=OFF;
  170. BEGIN;
  171. UPDATE t1 SET c=c-1;
  172. PRAGMA lock_status;
  173. }
  174. } {main reserved temp unknown} ;# No cache spill, so no exclusive lock
  175. # Verify that newly attached databases inherit the cache_spill=OFF
  176. # setting.
  177. #
  178. do_execsql_test pragma2-4.6 {
  179. COMMIT;
  180. ATTACH 'test2.db' AS aux1;
  181. PRAGMA aux1.cache_size=50;
  182. BEGIN;
  183. UPDATE t2 SET c=c+1;
  184. PRAGMA lock_status;
  185. } {main unlocked temp unknown aux1 reserved}
  186. do_execsql_test pragma2-4.7 {
  187. COMMIT;
  188. }
  189. sqlite3_release_memory
  190. do_execsql_test pragma2-4.8 {
  191. PRAGMA cache_spill=ON; -- Applies to all databases
  192. BEGIN;
  193. UPDATE t2 SET c=c-1;
  194. PRAGMA lock_status;
  195. } {main unlocked temp unknown aux1 exclusive}
  196. finish_test