sessionnoact.test 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # 2023 October 20
  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 sessionnoact
  20. do_execsql_test 1.0 {
  21. CREATE TABLE p1(a INTEGER PRIMARY KEY, b, c UNIQUE);
  22. INSERT INTO p1 VALUES(1, 1, 'one');
  23. INSERT INTO p1 VALUES(2, 2, 'two');
  24. INSERT INTO p1 VALUES(3, 3, 'three');
  25. INSERT INTO p1 VALUES(4, 4, 'four');
  26. }
  27. db_save
  28. set C [changeset_from_sql {
  29. DELETE FROM p1 WHERE a=2;
  30. UPDATE p1 SET c='six' WHERE a=3;
  31. INSERT INTO p1 VALUES(5, 5, 'two');
  32. INSERT INTO p1 VALUES(6, 6, 'three');
  33. }]
  34. db_restore_and_reopen
  35. do_execsql_test 1.1 {
  36. CREATE TABLE c1(x INTEGER PRIMARY KEY, y,
  37. FOREIGN KEY(y) REFERENCES p1(c) ON DELETE CASCADE ON UPDATE SET NULL
  38. );
  39. INSERT INTO c1 VALUES(10, 'one');
  40. INSERT INTO c1 VALUES(20, 'two');
  41. INSERT INTO c1 VALUES(30, 'three');
  42. INSERT INTO c1 VALUES(40, 'four');
  43. }
  44. db_save
  45. do_execsql_test 1.2 {
  46. PRAGMA foreign_keys = 1;
  47. }
  48. set ::nConflict 0
  49. proc conflict {args} {
  50. incr ::nConflict
  51. return "OMIT"
  52. }
  53. sqlite3changeset_apply_v2 db $C conflict
  54. do_execsql_test 1.3 {
  55. SELECT * FROM c1
  56. } {
  57. 10 one
  58. 30 {}
  59. 40 four
  60. }
  61. db_restore_and_reopen
  62. do_execsql_test 1.4 {
  63. PRAGMA foreign_keys = 1;
  64. }
  65. do_execsql_test 1.5 {
  66. UPDATE p1 SET c=12345 WHERE a = 45;
  67. }
  68. breakpoint
  69. sqlite3changeset_apply_v2 -noaction db $C conflict
  70. do_execsql_test 1.6 {
  71. SELECT * FROM c1
  72. } {
  73. 10 one
  74. 20 two
  75. 30 three
  76. 40 four
  77. }
  78. do_execsql_test 1.7 {
  79. PRAGMA foreign_keys = 1;
  80. UPDATE p1 SET c = 'ten' WHERE c='two';
  81. SELECT * FROM c1;
  82. } {
  83. 10 one
  84. 20 {}
  85. 30 three
  86. 40 four
  87. }
  88. do_execsql_test 1.8 {
  89. PRAGMA foreign_key_check
  90. }
  91. finish_test