rspec/rules/S1732/cobol/rule.adoc

46 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Explicitly defining a cursor as read-only can improve performance by avoiding table locking. This allows other SQL requests to execute in parallel. Therefore when a cursor will only be used to read data, without modifying anything, the ``++FOR READ ONLY++`` clause or its synonyn, ``++FOR FETCH ONLY++``, should be used.
Conversely when a cursor will modify data, that too should be specified using the ``++FOR UPDATE++`` clause.
In short, it's better to always explicitly define the purpose of the cursor with help of the ``++FOR READ ONLY++``, ``++FOR FETCH ONLY++`` or ``++FOR UPDATE++`` clauses.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cobol]
2021-04-28 16:49:39 +02:00
----
EXEC SQL DECLARE CMAJ_0A CURSOR
FOR SELECT C_BQ
FROM S1ORDCOU
WHERE C_BQ = :TORD-C-BQ
END-EXEC
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cobol]
2021-04-28 16:49:39 +02:00
----
EXEC SQL DECLARE CMAJ_0A CURSOR
FOR SELECT C_BQ
FROM S1ORDCOU
WHERE C_BQ = :TORD-C-BQ
FOR READ ONLY
END-EXEC
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]