savepoint7.test 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # 2012 March 31
  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. # Focus on the interaction between RELEASE and ROLLBACK TO with
  13. # pending query aborts. See ticket [27ca74af3c083f787a1c44b11fbb7c53bdbbcf1e].
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # The RELEASE of an inner savepoint should not effect pending queries.
  18. #
  19. do_test savepoint7-1.1 {
  20. db eval {
  21. CREATE TABLE t1(a,b,c);
  22. CREATE TABLE t2(x,y,z);
  23. INSERT INTO t1 VALUES(1,2,3);
  24. INSERT INTO t1 VALUES(4,5,6);
  25. INSERT INTO t1 VALUES(7,8,9);
  26. SAVEPOINT x1;
  27. }
  28. db eval {SELECT * FROM t1} {
  29. db eval {
  30. SAVEPOINT x2;
  31. INSERT INTO t2 VALUES($a,$b,$c);
  32. RELEASE x2;
  33. }
  34. }
  35. db eval {SELECT * FROM t2; RELEASE x1}
  36. } {1 2 3 4 5 6 7 8 9}
  37. do_test savepoint7-1.2 {
  38. db eval {DELETE FROM t2;}
  39. db eval {SELECT * FROM t1} {
  40. db eval {
  41. SAVEPOINT x2;
  42. INSERT INTO t2 VALUES($a,$b,$c);
  43. RELEASE x2;
  44. }
  45. }
  46. db eval {SELECT * FROM t2}
  47. } {1 2 3 4 5 6 7 8 9}
  48. do_test savepoint7-1.3 {
  49. db eval {DELETE FROM t2; BEGIN;}
  50. db eval {SELECT * FROM t1} {
  51. db eval {
  52. SAVEPOINT x2;
  53. INSERT INTO t2 VALUES($a,$b,$c);
  54. RELEASE x2;
  55. }
  56. }
  57. db eval {SELECT * FROM t2; ROLLBACK;}
  58. } {1 2 3 4 5 6 7 8 9}
  59. # However, a ROLLBACK of an inner savepoint will abort all queries, including
  60. # queries in outer contexts.
  61. #
  62. do_test savepoint7-2.1 {
  63. db eval {DELETE FROM t2; SAVEPOINT x1;}
  64. set rc [catch {
  65. db eval {SELECT * FROM t1} {
  66. db eval {
  67. SAVEPOINT x2;
  68. INSERT INTO t2 VALUES($a,$b,$c);
  69. ROLLBACK TO x2;
  70. }
  71. }
  72. } msg]
  73. db eval {RELEASE x1}
  74. list $rc $msg [db eval {SELECT * FROM t2}]
  75. } {1 {callback requested query abort} {}}
  76. do_test savepoint7-2.2 {
  77. db eval {DELETE FROM t2;}
  78. set rc [catch {
  79. db eval {SELECT * FROM t1} {
  80. db eval {
  81. SAVEPOINT x2;
  82. INSERT INTO t2 VALUES($a,$b,$c);
  83. ROLLBACK TO x2;
  84. }
  85. }
  86. } msg]
  87. list $rc $msg [db eval {SELECT * FROM t2}]
  88. } {1 {callback requested query abort} {}}
  89. finish_test