× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

I have a commitment control issue which we can't resolve and in my opinion, it should not work in that way.
Even if there is some wrong logic in below code, I can't understand why some transaction runs under commit while they should not.
The problem here is that update on TESTTABLE run under commit but actual trigger has commit=*none. Next time it run's properly without commit and in another loop it run under commit again(in TESTPGM I do updates in loop and it looks every run it behave differently).
The weirdest thing is that it works just fine if I'll simply remove exec sql select... from program TESTPGM
After I've added exec sql select... to pgm TESTPGM, weird things start to happen with some transaction's run under commit why they should not because of triggers compiled with commit=*none
I can't understand why this one simple sql select break the whole setup. Everything works just fine without embeded sql used in program.

DROP TABLE TESTLIB.TESTTABLE;

CREATE TABLE TESTLIB.TESTTABLE (
ID INTEGER GENERATED ALWAYS AS IDENTITY,
CODE INTEGER NOT NULL,
DESC CHAR(10) NOT NULL)

INSERT
INTO TESTLIB.TESTTABLE (CODE, DESC)
VALUES (1, ''), (2, '');

CREATE TABLE TESTLIB.TESTMQT ( TESTCODE, TESTDESC ) AS
(SELECT DECIMAL(CODE, 5), DESC
FROM TESTLIB.TESTTABLE)
DATA INITIALLY IMMEDIATE
REFRESH DEFERRED
ENABLE QUERY OPTIMIZATION
MAINTAINED BY USER
RCDFMT TESTMQT ;

CREATE UNIQUE INDEX TESTLIB.TESTIDX
ON TESTLIB.TESTMQT (TESTCODE);

CREATE OR REPLACE TRIGGER TESTLIB.TESTTRGUP
NO CASCADE BEFORE Update On TESTLIB.TESTMQT
REFERENCING OLD As vOld
NEW As vNew
For Each Row Mode DB2ROW
SET OPTION COMMIT=*NONE
BEGIN ATOMIC
UPDATE TESTLIB.TESTTABLE
SET
CODE = vNew.TESTCODE,
DESC = vNew.TESTDESC
WHERE
CODE = vOld.TESTCODE;
END;

CREATE TABLE TESTLIB.TESTPF ( TESTCOL CHAR(10) NOT NULL)
RCDFMT TESTRF;

CREATE TABLE TESTLIB.TESTTBL(
ID INTEGER GENERATED ALWAYS AS IDENTITY,
COLUMN CHAR(10) NOT NULL)

CREATE OR REPLACE TRIGGER TESTLIB.TESTPFTRGUP
NO CASCADE BEFORE Update On TESTLIB.TESTPF
REFERENCING OLD As vOld
NEW As vNew
For Each Row Mode DB2ROW
SET OPTION COMMIT=*NONE
BEGIN ATOMIC
UPDATE TESTLIB.TESTTBL
SET
COLUMN = vNew.TESTCOL
WHERE
COLUMN = vOld.TESTCOL;
END;

INSERT INTO TESTLIB.TESTPF VALUES '';



TESTCL.CLLE

PGM
STRCMTCTL LCKLVL(*CHG) CMTSCOPE(*JOB)
CALL TESTPGM
COMMIT
ENDCMTCTL
ENDPGM


TESTPGM.RPGLE

**FREE
Ctl-Opt DATEDIT(*DMY/) Option(*nodebugio:*srcstmt);

Dcl-F TESTPF Usage(*Update:*Delete:*Output) Commit;
Dcl-F TESTIDX Usage(*Update:*Delete:*Output) Keyed ;
Dcl-S Index Packed(4) Inz(0);
dcl-s id int(5);

exec sql set option commit=*none;
exec sql select id into :id from testtable limit 1;

Dow Index < 100;
Setll(e) *start TESTPF;
Read(e) TESTPF;
TESTCOL = %Char(Index+1);
Update(e) TESTRF;

Chain(e) (2) TESTIDX;
TESTDESC = %Char(Index);
Update(e) TESTMQT;

Chain(e) (1) TESTIDX;
TESTDESC = %Char(Index);
Update(e) TESTMQT;

Setll(e) *start TESTPF;
Read(e) TESTPF;
TESTCOL = %Char(Index);
Update(e) TESTRF;

Index+=1;
EndDo;

*INLR = *on;
Filip Drzewiecki
RPG Developer

e-mail: fdrzewiecki@xxxxxxxxxxxxxxxxx<mailto:fdrzewiecki@xxxxxxxxxxxxxxxxx>

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.