aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2014-05-08 14:16:21 -0400
committerEugeniy Mikhailov <evgmik@gmail.com>2014-05-08 14:16:21 -0400
commitdf447609e7ba90a7c3347ce7f4283430c9a69d6e (patch)
treefc06b525f4aee69e539dbfe6d40d2ba545e2fe21
parentc7bf8096b90e4f688603892093d8596a352c2ad5 (diff)
downloadGradeBook-df447609e7ba90a7c3347ce7f4283430c9a69d6e.tar.gz
GradeBook-df447609e7ba90a7c3347ce7f4283430c9a69d6e.zip
transaction end/begin enhanced to have force flags
-rwxr-xr-xlibBasicTableOperations.tcl37
1 files changed, 27 insertions, 10 deletions
diff --git a/libBasicTableOperations.tcl b/libBasicTableOperations.tcl
index 70b8dab..ff52f31 100755
--- a/libBasicTableOperations.tcl
+++ b/libBasicTableOperations.tcl
@@ -111,8 +111,10 @@ proc DeleteColumnFromTable { table columnname } {
}
set beginTransactionCounter 0
-proc begin_db_transaction { } {
+proc begin_db_transaction { {do_not_begin {false}} } {
+ # do_not_begin intended for restoring transaction state asseses previously
global beginTransactionCounter
+ if { $do_not_begin } { return }
incr beginTransactionCounter
if { $beginTransactionCounter == 1 } {
# starting transaction
@@ -125,17 +127,32 @@ proc begin_db_transaction { } {
}
}
-proc end_db_transaction { } {
+proc getTransactionState { } {
global beginTransactionCounter
+ if { $beginTransactionCounter >= 1 } {
+ return true
+ }
+ return false
+}
+
+
+
+proc end_db_transaction { {force_end {false}} } {
+ # force_end == true ends all transactions
+ global beginTransactionCounter
+ if { $force_end && ( $beginTransactionCounter >= 1) } {
+ set beginTransactionCounter 1
+ }
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
- }
+ if { ($beginTransactionCounter == 0) } {
+ # 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
+}
+ }
}