sessionrowid.test 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # 2011 Mar 16
  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. # The focus of this file is testing the session module.
  13. #
  14. if {![info exists testdir]} {
  15. set testdir [file join [file dirname [info script]] .. .. test]
  16. }
  17. source [file join [file dirname [info script]] session_common.tcl]
  18. source $testdir/tester.tcl
  19. ifcapable !session {finish_test; return}
  20. set testprefix sessionrowid
  21. do_execsql_test 0.0 {
  22. CREATE TABLE t1(a, b);
  23. }
  24. foreach {tn rowid bEmpty} {
  25. 1 0 1
  26. 2 1 0
  27. 3 -1 1
  28. } {
  29. do_test 0.$tn {
  30. sqlite3session S db main
  31. if {$rowid>=0} { S object_config rowid $rowid }
  32. S attach t1
  33. execsql { INSERT INTO t1 VALUES(1, 2); }
  34. expr [string length [S changeset]]==0
  35. } $bEmpty
  36. S delete
  37. }
  38. #-------------------------------------------------------------------------
  39. reset_db
  40. do_execsql_test 1.0 {
  41. CREATE TABLE t1(a, b);
  42. }
  43. do_iterator_test 1.1 t1 {
  44. INSERT INTO t1 VALUES('i', 'one');
  45. } {
  46. {INSERT t1 0 X.. {} {i 1 t i t one}}
  47. }
  48. do_execsql_test 1.2 {
  49. SELECT rowid, * FROM t1
  50. } {1 i one}
  51. do_iterator_test 1.3 t1 {
  52. UPDATE t1 SET b='two'
  53. } {
  54. {UPDATE t1 0 X.. {i 1 {} {} t one} {{} {} {} {} t two}}
  55. }
  56. do_iterator_test 1.4 t1 {
  57. DELETE FROM t1;
  58. } {
  59. {DELETE t1 0 X.. {i 1 t i t two} {}}
  60. }
  61. do_iterator_test 1.5 t1 {
  62. INSERT INTO t1(rowid, a, b) VALUES(14, 'hello', 'world');
  63. INSERT INTO t1(rowid, a, b) VALUES(NULL, 'yes', 'no');
  64. INSERT INTO t1(rowid, a, b) VALUES(-123, 'ii', 'iii');
  65. } {
  66. {INSERT t1 0 X.. {} {i -123 t ii t iii}}
  67. {INSERT t1 0 X.. {} {i 15 t yes t no}}
  68. {INSERT t1 0 X.. {} {i 14 t hello t world}}
  69. }
  70. do_iterator_test 1.6 t1 {
  71. UPDATE t1 SET a='deluxe' WHERE rowid=14;
  72. DELETE FROM t1 WHERE rowid=-123;
  73. INSERT INTO t1 VALUES('x', 'xi');
  74. } {
  75. {DELETE t1 0 X.. {i -123 t ii t iii} {}}
  76. {UPDATE t1 0 X.. {i 14 t hello {} {}} {{} {} t deluxe {} {}}}
  77. {INSERT t1 0 X.. {} {i 16 t x t xi}}
  78. }
  79. #-------------------------------------------------------------------------
  80. reset_db
  81. forcedelete test.db2
  82. sqlite3 db2 test.db2
  83. do_execsql_test 2.0 {
  84. CREATE TABLE t1(a, b);
  85. }
  86. do_execsql_test -db db2 2.0.1 {
  87. CREATE TABLE t1(a, b);
  88. }
  89. proc xConflict {args} {
  90. puts "CONFLICT!"
  91. return "OMIT"
  92. }
  93. do_test 2.1 {
  94. set C [changeset_from_sql {
  95. INSERT INTO t1 VALUES('abc', 'def');
  96. }]
  97. sqlite3changeset_apply db2 $C xConflict
  98. execsql { SELECT * FROM t1 } db2
  99. } {abc def}
  100. do_test 2.2 {
  101. set C [changeset_from_sql {
  102. UPDATE t1 SET b='hello'
  103. }]
  104. sqlite3changeset_apply db2 $C xConflict
  105. execsql { SELECT * FROM t1 } db2
  106. } {abc hello}
  107. do_test 2.3 {
  108. set C [changeset_from_sql {
  109. DELETE FROM t1 WHERE b='hello'
  110. }]
  111. sqlite3changeset_apply db2 $C xConflict
  112. execsql { SELECT * FROM t1 } db2
  113. } {}
  114. do_test 2.4 {
  115. do_then_apply_sql {
  116. INSERT INTO t1 VALUES('i', 'one');
  117. INSERT INTO t1 VALUES('ii', 'two');
  118. INSERT INTO t1 VALUES('iii', 'three');
  119. INSERT INTO t1 VALUES('iv', 'four');
  120. }
  121. compare_db db db2
  122. } {}
  123. do_test 2.5 {
  124. do_then_apply_sql {
  125. DELETE FROM t1 WHERE a='ii';
  126. UPDATE t1 SET b='THREE' WHERE a='iii';
  127. UPDATE t1 SET a='III' WHERE a='iii';
  128. INSERT INTO t1 VALUES('v', 'five');
  129. }
  130. compare_db db db2
  131. } {}
  132. do_execsql_test 2.6 {SELECT * FROM t1} {i one III THREE iv four v five}
  133. do_execsql_test -db db2 2.7 {SELECT * FROM t1} {i one III THREE iv four v five}
  134. #-------------------------------------------------------------------------
  135. db2 close
  136. reset_db
  137. forcedelete test.db2
  138. sqlite3 db2 test.db2
  139. set init_sql {
  140. CREATE TABlE t4(a, b);
  141. CREATE INDEX t4a ON t4(a);
  142. CREATE UNIQUE INDEX t4b ON t4(b);
  143. }
  144. do_execsql_test 3.0 $init_sql
  145. do_execsql_test -db db2 3.0a $init_sql
  146. do_execsql_test -db db2 3.1 {
  147. INSERT INTO t4(rowid, a, b) VALUES(43, 'hello', 'world');
  148. }
  149. do_conflict_test 3.2 -sql {
  150. INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
  151. } -tables t4 -conflicts {
  152. {INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
  153. }
  154. do_execsql_test -db db2 3.3 {
  155. SELECT * FROM t4
  156. } {hello world}
  157. do_execsql_test 3.4 { DELETE FROM t4 }
  158. do_conflict_test 3.5 -sql {
  159. INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
  160. } -tables t4 -conflicts {
  161. {INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
  162. } -policy REPLACE
  163. do_execsql_test -db db2 3.6 {
  164. SELECT * FROM t4
  165. } {abc def}
  166. do_execsql_test 3.7 { DELETE FROM t4 }
  167. do_conflict_test 3.8 -sql {
  168. INSERT INTO t4(rowid, a, b) VALUES(45, 'xyz', 'def');
  169. } -tables t4 -conflicts {
  170. {INSERT t4 CONSTRAINT {i 45 t xyz t def}}
  171. }
  172. do_execsql_test -db db2 3.9 {
  173. SELECT * FROM t4
  174. } {abc def}
  175. do_execsql_test -db db 3.10a { DELETE FROM t4 }
  176. do_execsql_test -db db2 3.10b { DELETE FROM t4 }
  177. do_execsql_test -db db 3.11a {
  178. INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
  179. INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
  180. }
  181. do_execsql_test -db db2 3.11b {
  182. INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
  183. }
  184. do_conflict_test 3.12 -sql {
  185. DELETE FROM t4 WHERE a='one';
  186. } -tables t4 -conflicts {
  187. {DELETE t4 DATA {i 111 t one t one} {i 111 t one t blip}}
  188. }
  189. do_execsql_test -db db2 3.13 {
  190. SELECT * FROM t4
  191. } {one blip}
  192. do_conflict_test 3.14 -sql {
  193. DELETE FROM t4 WHERE a='two';
  194. } -tables t4 -conflicts {
  195. {DELETE t4 NOTFOUND {i 222 t two t two}}
  196. }
  197. do_execsql_test -db db2 3.15 {
  198. SELECT * FROM t4
  199. } {one blip}
  200. do_execsql_test -db db 3.16a { DELETE FROM t4 }
  201. do_execsql_test -db db2 3.16b { DELETE FROM t4 }
  202. do_execsql_test -db db 3.17a {
  203. INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
  204. INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
  205. }
  206. do_execsql_test -db db2 3.17b {
  207. INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
  208. }
  209. do_conflict_test 3.18 -sql {
  210. UPDATE t4 SET b='xyz' WHERE a='one'
  211. } -tables t4 -conflicts {
  212. {UPDATE t4 DATA {i 111 {} {} t one} {{} {} {} {} t xyz} {i 111 t one t blip}}
  213. }
  214. do_execsql_test -db db2 3.19 {
  215. SELECT * FROM t4
  216. } {one blip}
  217. do_conflict_test 3.20 -sql {
  218. UPDATE t4 SET b='123' WHERE a='two'
  219. } -tables t4 -conflicts {
  220. {UPDATE t4 NOTFOUND {i 222 {} {} t two} {{} {} {} {} t 123}}
  221. }
  222. do_execsql_test -db db2 3.21 {
  223. SELECT * FROM t4
  224. } {one blip}
  225. db2 close
  226. #--------------------------------------------------------------------------
  227. breakpoint
  228. do_diff_test 4.0 {
  229. CREATE TABLE t1(x, y);
  230. CREATE TABLE aux.t1(x, y);
  231. INSERT INTO t1 VALUES(1, 2);
  232. }
  233. do_diff_test 4.1 {
  234. CREATE TABLE t1(x, y);
  235. CREATE TABLE aux.t1(x, y);
  236. INSERT INTO aux.t1 VALUES(1, 2);
  237. }
  238. do_diff_test 4.2 {
  239. CREATE TABLE t1(x, y);
  240. CREATE TABLE aux.t1(x, y);
  241. INSERT INTO t1(rowid, x, y) VALUES(413, 'hello', 'there');
  242. INSERT INTO aux.t1(rowid, x, y) VALUES(413, 'hello', 'world');
  243. }
  244. finish_test