trans3.test 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # 2008 November 3
  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. # This file implements regression tests for SQLite library. The
  13. # focus of this script is the response of COMMIT and ROLLBACK when
  14. # statements are still pending.
  15. #
  16. # $Id: trans3.test,v 1.2 2008/11/05 16:37:35 drh Exp $
  17. #
  18. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. unset -nocomplain ecode
  21. do_test trans3-1.1 {
  22. db eval {
  23. CREATE TABLE t1(x);
  24. INSERT INTO t1 VALUES(1);
  25. INSERT INTO t1 VALUES(2);
  26. INSERT INTO t1 VALUES(3);
  27. SELECT * FROM t1;
  28. }
  29. } {1 2 3}
  30. do_test trans3-1.2 {
  31. db eval BEGIN
  32. db eval {INSERT INTO t1 VALUES(4);}
  33. set ::ecode {}
  34. set x [catch {
  35. db eval {SELECT * FROM t1 LIMIT 1} {
  36. if {[catch {db eval COMMIT} errmsg]} {
  37. set ::ecode [sqlite3_extended_errcode db]
  38. error $errmsg
  39. }
  40. }
  41. } errmsg]
  42. lappend x $errmsg
  43. } {0 {}}
  44. do_test trans3-1.3 {
  45. set ::ecode
  46. } {}
  47. do_test trans3-1.3.1 {
  48. sqlite3_get_autocommit db
  49. } 1
  50. do_test trans3-1.4 {
  51. db eval {SELECT * FROM t1}
  52. } {1 2 3 4}
  53. do_test trans3-1.5 {
  54. db eval BEGIN
  55. db eval {INSERT INTO t1 VALUES(5);}
  56. set ::ecode {}
  57. set x [catch {
  58. db eval {SELECT * FROM t1} {
  59. if {[catch {db eval ROLLBACK} errmsg]} {
  60. set ::ecode [sqlite3_extended_errcode db]
  61. error $errmsg
  62. }
  63. }
  64. } errmsg]
  65. lappend x $errmsg
  66. } {1 {abort due to ROLLBACK}}
  67. do_test trans3-1.6 {
  68. set ::ecode
  69. } {}
  70. do_test trans3-1.7 {
  71. db eval {SELECT * FROM t1}
  72. } {1 2 3 4}
  73. unset -nocomplain ecode
  74. finish_test