vtab4.test 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. # 2006 June 10
  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. The
  12. # focus is on testing the following virtual table methods:
  13. #
  14. # xBegin
  15. # xSync
  16. # xCommit
  17. # xRollback
  18. #
  19. # $Id: vtab4.test,v 1.3 2008/07/12 14:52:21 drh Exp $
  20. set testdir [file dirname $argv0]
  21. source $testdir/tester.tcl
  22. unset -nocomplain echo_module
  23. unset -nocomplain echo_module_sync_fail
  24. ifcapable !vtab {
  25. finish_test
  26. return
  27. }
  28. # Register the echo module
  29. db cache size 0
  30. register_echo_module [sqlite3_connection_pointer db]
  31. do_test vtab4-1.1 {
  32. execsql {
  33. CREATE TABLE treal(a PRIMARY KEY, b, c);
  34. CREATE VIRTUAL TABLE techo USING echo(treal);
  35. }
  36. } {}
  37. # Test an INSERT, UPDATE and DELETE statement on the virtual table
  38. # in an implicit transaction. Each should result in a single call
  39. # to xBegin, xSync and xCommit.
  40. #
  41. do_test vtab4-1.2 {
  42. set echo_module [list]
  43. execsql {
  44. INSERT INTO techo VALUES(1, 2, 3);
  45. }
  46. set echo_module
  47. } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
  48. do_test vtab4-1.3 {
  49. set echo_module [list]
  50. execsql {
  51. UPDATE techo SET a = 2;
  52. }
  53. set echo_module
  54. } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
  55. xBegin echo(treal) \
  56. xFilter {SELECT rowid, * FROM 'treal'} \
  57. xSync echo(treal) \
  58. xCommit echo(treal) \
  59. ]
  60. do_test vtab4-1.4 {
  61. set echo_module [list]
  62. execsql {
  63. DELETE FROM techo;
  64. }
  65. set echo_module
  66. } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
  67. xBegin echo(treal) \
  68. xFilter {SELECT rowid, * FROM 'treal'} \
  69. xSync echo(treal) \
  70. xCommit echo(treal) \
  71. ]
  72. # Ensure xBegin is not called more than once in a single transaction.
  73. #
  74. do_test vtab4-2.1 {
  75. set echo_module [list]
  76. execsql {
  77. BEGIN;
  78. INSERT INTO techo VALUES(1, 2, 3);
  79. INSERT INTO techo VALUES(4, 5, 6);
  80. INSERT INTO techo VALUES(7, 8, 9);
  81. COMMIT;
  82. }
  83. set echo_module
  84. } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
  85. # Try a transaction with two virtual tables.
  86. #
  87. do_test vtab4-2.2 {
  88. execsql {
  89. CREATE TABLE sreal(a, b, c UNIQUE);
  90. CREATE VIRTUAL TABLE secho USING echo(sreal);
  91. }
  92. set echo_module [list]
  93. execsql {
  94. BEGIN;
  95. INSERT INTO secho SELECT * FROM techo;
  96. DELETE FROM techo;
  97. COMMIT;
  98. }
  99. set echo_module
  100. } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
  101. xBegin echo(sreal) \
  102. xFilter {SELECT rowid, * FROM 'treal'} \
  103. xBestIndex {SELECT rowid, * FROM 'treal'} \
  104. xBegin echo(treal) \
  105. xFilter {SELECT rowid, * FROM 'treal'} \
  106. xSync echo(sreal) \
  107. xSync echo(treal) \
  108. xCommit echo(sreal) \
  109. xCommit echo(treal) \
  110. ]
  111. do_test vtab4-2.3 {
  112. execsql {
  113. SELECT * FROM secho;
  114. }
  115. } {1 2 3 4 5 6 7 8 9}
  116. do_test vtab4-2.4 {
  117. execsql {
  118. SELECT * FROM techo;
  119. }
  120. } {}
  121. # Try an explicit ROLLBACK on a transaction with two open virtual tables.
  122. do_test vtab4-2.5 {
  123. set echo_module [list]
  124. execsql {
  125. BEGIN;
  126. INSERT INTO techo SELECT * FROM secho;
  127. DELETE FROM secho;
  128. ROLLBACK;
  129. }
  130. set echo_module
  131. } [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
  132. xBegin echo(treal) \
  133. xFilter {SELECT rowid, * FROM 'sreal'} \
  134. xBestIndex {SELECT rowid, * FROM 'sreal'} \
  135. xBegin echo(sreal) \
  136. xFilter {SELECT rowid, * FROM 'sreal'} \
  137. xRollback echo(treal) \
  138. xRollback echo(sreal) \
  139. ]
  140. do_test vtab4-2.6 {
  141. execsql {
  142. SELECT * FROM secho;
  143. }
  144. } {1 2 3 4 5 6 7 8 9}
  145. do_test vtab4-2.7 {
  146. execsql {
  147. SELECT * FROM techo;
  148. }
  149. } {}
  150. do_test vtab4-3.1 {
  151. set echo_module [list]
  152. set echo_module_sync_fail treal
  153. catchsql {
  154. INSERT INTO techo VALUES(1, 2, 3);
  155. }
  156. } {1 {unknown error}}
  157. do_test vtab4-3.2 {
  158. set echo_module
  159. } {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)}
  160. do_test vtab4-3.3 {
  161. set echo_module [list]
  162. set echo_module_sync_fail sreal
  163. catchsql {
  164. BEGIN;
  165. INSERT INTO techo SELECT * FROM secho;
  166. DELETE FROM secho;
  167. COMMIT;
  168. }
  169. set echo_module
  170. } [list xBestIndex {SELECT rowid, * FROM 'sreal'} \
  171. xBegin echo(treal) \
  172. xFilter {SELECT rowid, * FROM 'sreal'} \
  173. xBestIndex {SELECT rowid, * FROM 'sreal'} \
  174. xBegin echo(sreal) \
  175. xFilter {SELECT rowid, * FROM 'sreal'} \
  176. xSync echo(treal) \
  177. xSync echo(sreal) \
  178. xRollback echo(treal) \
  179. xRollback echo(sreal) \
  180. ]
  181. finish_test