Subject | Re: wait transactions and rollback |
---|---|
Author | tsoyran |
Post date | 2002-07-06T22:26:20Z |
I am reading this conversation and I like it a lot.
I have the same problem for an other reason.
I am developing an application for with Firebird and AS400/DB2.
In the later there are no generators so in both cases
even I don't need consecutive numbers for each type of counter I have
to use
the "separate table containing TableNames values and the counter ID"
If I read well (due to my language) this is the preferred solution:
===== mixed SQL,pascal,text language ====================
other_error := false;
retry := false;
Repeat
Succeeded := False;
Tries := 0;
Repeat
Db.Starttransaction;
Try
/* Get Counter Value */
SELECT COUNTER
FROM TABLE_KEYS
WHERE TABLE_NAME = XXXX;
/* Try to Update - Lock
if we failed here the exception fires ... */
UPDATE TABLE_KEYS
SET COUNTER = COUNTER
WHERE TABLE_NAME = XXXX;
/* the record is unlocked then we update it with the real
value */
New_Counter := Counter + 1;
UPDATE TABLE_KEYS
SET COUNTER= :New_Counter
WHERE TABLE_NAME = XXXX;
Db.Commit;
Succeeded := True;
Except
Db.Rollback;
if Error = LOCK_CONFLICT Then
Inc(Tries);
else
other_error := true;
End;
Until (Tries=MAX_TRIES) or Succeeded;
If No Succeeded and not other_error Then
If Messagedlg('There Record were Locked from an Other User'+#13+
'I tried NN Times'
'What Do You Want For Me To Do?',
mtconfirmation,[mbRetry,mbCancel]) = mrRetry then
retry := true;
Until not retry;
/* exit conditions
if succeeded = true then
the new ID is the New_Counter we can proceed
else
we cannot proceed
if other_error = true
something else made the failure
else
if retry = false
the user tired retrying
*/
======== END ==================
Thanks a Lot
Antonis Tsourinakis
I have the same problem for an other reason.
I am developing an application for with Firebird and AS400/DB2.
In the later there are no generators so in both cases
even I don't need consecutive numbers for each type of counter I have
to use
the "separate table containing TableNames values and the counter ID"
If I read well (due to my language) this is the preferred solution:
===== mixed SQL,pascal,text language ====================
other_error := false;
retry := false;
Repeat
Succeeded := False;
Tries := 0;
Repeat
Db.Starttransaction;
Try
/* Get Counter Value */
SELECT COUNTER
FROM TABLE_KEYS
WHERE TABLE_NAME = XXXX;
/* Try to Update - Lock
if we failed here the exception fires ... */
UPDATE TABLE_KEYS
SET COUNTER = COUNTER
WHERE TABLE_NAME = XXXX;
/* the record is unlocked then we update it with the real
value */
New_Counter := Counter + 1;
UPDATE TABLE_KEYS
SET COUNTER= :New_Counter
WHERE TABLE_NAME = XXXX;
Db.Commit;
Succeeded := True;
Except
Db.Rollback;
if Error = LOCK_CONFLICT Then
Inc(Tries);
else
other_error := true;
End;
Until (Tries=MAX_TRIES) or Succeeded;
If No Succeeded and not other_error Then
If Messagedlg('There Record were Locked from an Other User'+#13+
'I tried NN Times'
'What Do You Want For Me To Do?',
mtconfirmation,[mbRetry,mbCancel]) = mrRetry then
retry := true;
Until not retry;
/* exit conditions
if succeeded = true then
the new ID is the New_Counter we can proceed
else
we cannot proceed
if other_error = true
something else made the failure
else
if retry = false
the user tired retrying
*/
======== END ==================
Thanks a Lot
Antonis Tsourinakis