
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.
44 lines
1.1 KiB
Plaintext
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
|
|
----
|
|
|