Consultor Eletrônico



Kbase P1224: 4GL. Which Statement will start a Transaction by default?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   30/07/2007
Status: Verified

GOAL:

Which Statement will start a Transaction by default?

GOAL:

What are the 4GL statements that will start a transaction?

GOAL:

4GL Statements that starts a transaction

FACT(s) (Environment):

Progress 8.x
Progress 9.x
OpenEdge 10

FIX:

Transaction are one of the fundamental elements of Progress.
The Progress Transactions are linked to the procedures and to the procedure blocks. Certain Procedure Blocks will also start a Transaction by default, this means that a Transaction can start in one of the following blocks:

- A Procedure (Internal or External).
- A Trigger block.
- A REPEAT Block.
- A FOR EACH Block.
- A DO TRANSACTION Block.

Progress also start a Transaction by default in each iteration of the block of highest level.
This means if the block contains:
A. one of the following STATEMENTS:

- ASSIGN over a DB Field.
- UPDATE.
- SET.
- INSERT.
- CREATE.
- DELETE.

B. An instruction for Reading one or more records with EXCLUSIVE-LOCK.

Example:
This example will fail and will create duplicate records because the TRANSACTION starts in a CREATE and the record is not released.


DEF VAR t AS INT NO-UNDO.
DEF VAR r AS INT NO-UNDO.
DEF VAR h_gang AS CHAR NO-UNDO.
DEFINE TEMP-TABLE t_test NO-UNDO
FIELD gang AS CHAR
FIELD mom AS INT INITIAL ?
INDEX test IS PRIMARY gang mom.

DO t = 1 TO 5000:
r = RANDOM(0,25).
h_gang = CHR(ASC("a") + r).
IF NOT CAN-FIND(FIRST t_test
WHERE t_test.gang = h_gang
AND t_test.mom = ?) THEN DO:
FIND FIRST t_test
WHERE t_test.gang = h_gang
AND t_test.mom = ?
NO-ERROR.
IF AVAIL t_test THEN DO:
MESSAGE t_test.gang "already exists".
PAUSE.
END.
CREATE t_test.
t_test.gang = h_gang.
END.
END.
FOR EACH t_test NO-LOCK.
DISP t_test.gang.
END.

The correction will be to put a REPEAT (Because it will start a transaction) instead of DO t = 1 to 5000, or to DO TRANSACTION: before the create, or if you do not want to start a Transaction to force a RELEASE record.

Within a Transaction a record is released at the end of a TRANSACTION.