rspec/rules/S3890/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

44 lines
1.1 KiB
Plaintext

== Why is this an issue?
After the execution of each SQL statement (other than ``++DECLARE CURSOR++``, ``++DECLARE TABLE++`` and ``++DECLARE VARIABLE++``), the value of ``++SQLCODE++`` or ``++SQLSTATE++`` should be checked before proceeding. A 0 ``++SQLCODE++`` value means the statement succeeded, a positive value means success with a warning, and a negative value indicates an error. Proceeding without checking could put your program or your data in a bad state.
=== Noncompliant code example
[source,text]
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
DISPLAY username. *> Noncompliant
----
=== Compliant solution
[source,text]
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
IF SQLCODE = 0 THEN
DISPLAY username
END-IF.
----
=== Exceptions
When the value of ``++SQLCODE++`` or ``++SQLSTATE++`` is not checked but transferred to another variable for later use, no issue is raised.
[source,text]
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
MOVE SQLCODE TO SQL-RETURN-CODE
----