rspec/rules/S2535/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

77 lines
1.4 KiB
Plaintext

== Why is this an issue?
``++EXECUTE IMMEDIATE++`` is easier to use and understand than the DBMS_SQL package's procedures. It should therefore be preferred, when possible.
=== Noncompliant code example
[source,sql]
----
SET SERVEROUTPUT ON
CREATE TABLE myTable(
foo VARCHAR2(42)
);
CREATE PROCEDURE drop_table(tableName VARCHAR2) AS
cursorIdentifier INTEGER;
BEGIN
cursorIdentifier := DBMS_SQL.OPEN_CURSOR; -- Compliant; this is not a procedure call
DBMS_SQL.PARSE(cursorIdentifier, 'DROP TABLE ' || tableName, DBMS_SQL.NATIVE); -- Noncompliant
DBMS_SQL.CLOSE_CURSOR(cursorIdentifier); -- Noncompliant
DBMS_OUTPUT.PUT_LINE('Table ' || tableName || ' dropped.');
EXCEPTION
WHEN OTHERS THEN
DBMS_SQL.CLOSE_CURSOR(cursorIdentifier); -- Noncompliant
END;
/
BEGIN
drop_table('myTable');
END;
/
DROP PROCEDURE drop_table;
----
=== Compliant solution
[source,sql]
----
SET SERVEROUTPUT ON
CREATE TABLE myTable(
foo VARCHAR2(42)
);
CREATE PROCEDURE drop_table(tableName VARCHAR2) AS
cursorIdentifier INTEGER;
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE ' || tableName;
DBMS_OUTPUT.PUT_LINE('Table ' || tableName || ' dropped.');
END;
/
BEGIN
drop_table('myTable');
END;
/
DROP PROCEDURE drop_table;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use "EXECUTE IMMEDIATELY" instead of calling "xxx".
endif::env-github,rspecator-view[]