Assume that irispy is a connected instance of iris.IRIS (see “Creating a Connection in Python”).
Global array utility functions store_values(), show_values(), start_counters(), and show_counters() are listed immediately after this example (see “Global array utility functions”).
tlevel = irispy.getTLevel()
counters = start_counters()
action = 'Initial values:'.ljust(18,' ') + 'tLevel='+str(tlevel)
print(action + ', ' + show_counters() + ', ' + show_values() )
print('\nStore three values in three nested transaction levels:')
while tlevel < 3:
irispy.tStart() # start a new transaction, incrementing tlevel by 1
tlevel = irispy.getTLevel()
store_values(tlevel)
counters['add'] += 1 # increment with +=
irispy.increment(1,counters._global_name, 'inc') # call increment()
action = ' tStart:'.ljust(18,' ') + 'tLevel=' + str(tlevel)
print(action + ', ' + show_counters() + ', ' + show_values() )
print('\nNow roll back two levels and commit the level 1 transaction:')
while tlevel > 0:
if (tlevel>1):
irispy.tRollbackOne() # roll back to level 1
action = ' tRollbackOne():'
else:
irispy.tCommit() # commit level 1 transaction
action = ' tCommit():'
tlevel = irispy.getTLevel()
action = action.ljust(18,' ') + 'tLevel=' + str(tlevel)
print(action + ', ' + show_counters() + ', ' + show_values() )
Prints:
Initial values: tLevel=0, add=0/inc=0, values=[]
Store three values in three nested transaction levels:
tStart: tLevel=1, add=1/inc=1, values=["data1"]
tStart: tLevel=2, add=2/inc=2, values=["data1", "data2"]
tStart: tLevel=3, add=3/inc=3, values=["data1", "data2", "data3"]
Now roll back two levels and commit the level 1 transaction:
tRollbackOne(): tLevel=2, add=2/inc=3, values=["data1", "data2"]
tRollbackOne(): tLevel=1, add=1/inc=3, values=["data1"]
tCommit(): tLevel=0, add=1/inc=3, values=["data1"]