'Select Only' READ has 'FOR UPDATE' in Gen generated code
search cancel

'Select Only' READ has 'FOR UPDATE' in Gen generated code

book

Article ID: 244367

calendar_today

Updated On:

Products

Gen - Host Encyclopedia Gen - Run Time Distributed Gen - Workstation Toolset Gen

Issue/Introduction

There is an action block that has multiple READ statements with the (Select Only) flag set.  Following the READ statements is a CREATE that does an ASSOCIATE to the entities referenced in the READ statements.  The generated code creates a CURSOR FOR (with 'SELECT ... FOR UPDATE OF ...') for the READ statements.  Why is there a CURSOR FOR when the (Select Only) flag is set?

Action Block code:

+=>READ (Select Only) db_key Entity1
!        WHERE DESIRED db_key Entity1 Attr1 = Attr1nr
+> WHEN successful
+> WHEN not found
+--

+=>READ (Select Only) db_key Entity2
!        WHERE DESIRED db_key Entity2 Attr2 = Attr2nr
+> WHEN successful
+> WHEN not found
+--

+->CREATE Entity3
!  SET ... TO ...
!  ASSOCIATE WITH db_key Entity1 WHICH ... IT
!  ASSOCIATE WITH db_key Entity2 WHICH ... IT
+> WHEN successful
+> WHEN already exists
+--

Generated code:

EXEC SQL DECLARE CUR_1234567890_1 CURSOR FOR
SELECT
...
FOR UPDATE OF ...

Environment

Release : 8.6

Component : Gen Generators

Resolution

The CREATE statement is making ASSOCIATE calls that reference the entities that were just read.  So, the generator will always generate a cursor regardless of the 'Select Only' property because the row needs to be locked as it is being referenced in the UPDATE generated to do the ASSOCIATE.

Additional Information

Related article: SELECT 'FOR UPDATE' statements in Gen generated code