rspec/rules/S2570/plsql/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

68 lines
1.5 KiB
Plaintext

== Why is this an issue?
Weak ``++REF CURSOR++`` types are harder to work with than ones with a return type. Indeed, the compiler's type-checker is unable to make some verifications, which are then delayed till runtime.
When the use of weak ``++REF CURSOR++`` is required, it is best to use the ``++SYS_REFCURSOR++`` built-in type instead of defining a new one.
This rule's sysRefCursorAllowed parameter can be used to control whether or not the usage of ``++SYS_REFCURSOR++`` is allowed.
=== Noncompliant code example
[source,sql]
----
DECLARE
TYPE dualCursorType IS REF CURSOR; -- Noncompliant
dualCursor dualCursorType;
otherCursor SYS_REFCURSOR; -- Compliant or non-compliant, depending on the "sysRefCursorAllowed" parameter
BEGIN
otherCursor := dualCursor; -- Works
END;
/
----
=== Compliant solution
[source,sql]
----
DECLARE
TYPE dualCursorType IS REF CURSOR RETURN DUAL%ROWTYPE;
dualCursor dualCursorType;
TYPE otherCursorType IS REF CURSOR RETURN a%ROWTYPE;
otherCursor otherCursorType;
BEGIN
otherCursor := dualCursor; -- raises PLS-00382: expression is of wrong type, which makes debugging easier
END;
/
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add a return type to this "REF CURSOR".
=== Parameters
.sysRefCursorAllowed
****
----
false
----
Whether or not the use of "SYS_REFCURSOR" is allowed.
****
endif::env-github,rspecator-view[]