I'm having a problem with nested database transactions. According to the documentation for CAPI.EndTransaction:
Note that CAPI keeps a running tally of the number of times that CAPI.StartTransaction() has been called since the last CAPI.EndTransaction(). In order for a commit to actually take place, the number of StartTransactions for a given operation must be balanced by an equal number of EndTransactions and all EndTransactions must pass CAPI.COMMIT. This structure allows multiple levels of an application to all call StartTransaction and EndTransaction while still allowing the highest level of the code to maintain ultimate controls over the transaction. If, at any level, CAPI.ROLLBACK is passed, the entire transaction will be rolled back at that point.
The last line (in bold) is the part I'm struggling with. Consider the following code snippet. The admin server must be disabled (to prevent memcache in $LLIAPI.CacheUtil from having an influence):
Object prgCtx = $WebProspector.Utils.GetPrgCtx()Assoc resultsecho('-------')// start the outer transaction, which calls CAPI.StartTransaction()if prgCtx.fDbConnect.StartTrans() // start the inner transaction if prgCtx.fDbConnect.StartTrans() results = $LLIAPI.CacheUtil.New(prgCtx, "TEST VALUE") echo( \ "Inner: ", \ $LLIAPI.CacheUtil.Load(prgCtx, results.objectid) \ ) // rollback the inner transaction, which calls CAPI.EndTransaction() prgCtx.fDbConnect.EndTrans( false ) echo( \ "Outer 1: ", \ $LLIAPI.CacheUtil.Load(prgCtx, results.objectid) \ ) end // commit the outer transaction prgCtx.fDbConnect.EndTrans( true )endecho( \ "Outer 2: ", \ $LLIAPI.CacheUtil.Load(prgCtx, results.objectid) \ )The output from this is:
-------Inner: A<1,?,'apiError'=?,'errMsg'='','expires'=D/2015/3/8:13:36:35,'objectValue'='TEST VALUE','ok'=true>Outer 1: A<1,?,'apiError'=?,'errMsg'='','expires'=D/2015/3/8:13:36:35,'objectValue'='TEST VALUE','ok'=true>Outer 2: A<1,?,'apiError'=?,'errMsg'='','expires'=D/2015/3/8:13:36:35,'objectValue'='TEST VALUE','ok'=true>
I would have expected Outer 1 or at least Outer 2 to return an error since the inner transaction was rolled back and according to the documentation should have caused the entire transaction to be rolled back.
Can anyone confirm if this is a bug in the code, a documentation error, or if I'm doing something wrong? Thanks!