rspec/rules/S3890/rule.adoc

41 lines
1.0 KiB
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
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.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
DISPLAY username. *> Noncompliant
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
IF SQLCODE = 0 THEN
DISPLAY username
END-IF.
----
== Exceptions
2021-01-27 13:42:22 +01:00
When the value of ``++SQLCODE++`` or ``++SQLSTATE++`` is not checked but transferred to another variable for later use, no issue is raised.
2020-06-30 12:48:39 +02:00
----
EXEC SQL
SELECT name INTO :username FROM user WHERE id = :userid
END-EXEC.
MOVE SQLCODE TO SQL-RETURN-CODE
----