From 770a60b121c80a95b552c2698b11c5d52aa458ed Mon Sep 17 00:00:00 2001 From: Eugeniy Mikhailov Date: Thu, 8 May 2014 10:43:48 -0400 Subject: reworked transaction start/end logic now it is not closing if someone else wanted it started --- libBasicTableOperations.tcl | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libBasicTableOperations.tcl b/libBasicTableOperations.tcl index 04c6d00..70b8dab 100755 --- a/libBasicTableOperations.tcl +++ b/libBasicTableOperations.tcl @@ -110,11 +110,12 @@ proc DeleteColumnFromTable { table columnname } { } } -set isDbTransactionActive false +set beginTransactionCounter 0 proc begin_db_transaction { } { - global isDbTransactionActive - if { !$isDbTransactionActive } { - set isDbTransactionActive true + global beginTransactionCounter + incr beginTransactionCounter + if { $beginTransactionCounter == 1 } { + # starting transaction set eval_str [concat BEGIN TRANSACTION] set err [catch {db eval $eval_str } errStat] if { $err } { @@ -125,16 +126,16 @@ proc begin_db_transaction { } { } proc end_db_transaction { } { - global isDbTransactionActive - if { $isDbTransactionActive } { - set isDbTransactionActive false - set eval_str [concat END TRANSACTION] - set err [catch {db eval $eval_str } errStat] - if { $err } { - htmlErrorMsg $errStat end_db_transaction - dbg "the following error happen: $errStat" msg_level_critical begin_db_transaction - } - } + global beginTransactionCounter + incr beginTransactionCounter -1 + if { $beginTransactionCounter > 0 } return; + # closing transaction + set eval_str [concat END TRANSACTION] + set err [catch {db eval $eval_str } errStat] + if { $err } { + htmlErrorMsg $errStat end_db_transaction + dbg "the following error happen: $errStat" msg_level_critical begin_db_transaction + } } -- cgit v1.2.3