sessionconflict.test 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # 2011 March 07
  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. if {![info exists testdir]} {
  14. set testdir [file join [file dirname [info script]] .. .. test]
  15. }
  16. source [file join [file dirname [info script]] session_common.tcl]
  17. source $testdir/tester.tcl
  18. ifcapable !session {finish_test; return}
  19. set testprefix sessionconflict
  20. db close
  21. sqlite3_shutdown
  22. test_sqlite3_log log
  23. proc log {code msg} { puts "LOG $code $msg" }
  24. sqlite3 db test.db
  25. forcedelete test.db2
  26. sqlite3 db2 test.db2
  27. do_test 1.0 {
  28. do_common_sql {
  29. CREATE TABLE t1(a PRIMARY KEY, b, c UNIQUE);
  30. INSERT INTO t1 VALUES(1, 1, 1);
  31. INSERT INTO t1 VALUES(2, 2, 2);
  32. INSERT INTO t1 VALUES(3, 3, 3);
  33. }
  34. } {}
  35. do_execsql_test -db db2 1.1 {
  36. INSERT INTO t1 VALUES(6, 6, 6);
  37. }
  38. proc xConflict {args} {
  39. return "ABORT"
  40. }
  41. do_test 1.2 {
  42. set chng [changeset_from_sql {
  43. UPDATE t1 SET b=10, c=10 WHERE a=1;
  44. UPDATE t1 SET b=444 WHERE a=2;
  45. INSERT INTO t1 VALUES(4, 4, 4);
  46. INSERT INTO t1 VALUES(5, 5, 5);
  47. INSERT INTO t1 VALUES(6, 6, 6);
  48. }]
  49. execsql BEGIN db2
  50. set res [list [catch { sqlite3changeset_apply db2 $chng xConflict } msg] $msg]
  51. execsql ROLLBACK db2
  52. set res
  53. } {1 SQLITE_ABORT}
  54. do_execsql_test -db db2 1.3 {
  55. SELECT * FROM t1;
  56. } {
  57. 1 1 1
  58. 2 2 2
  59. 3 3 3
  60. 6 6 6
  61. }
  62. finish_test