Skip to content

Commit 2a0b3a2

Browse files
committed
Fix #81 - Removed G-7240 and replaced with G-7160 and G-7170
1 parent 2756153 commit 2a0b3a2

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# G-7160: Always explicitly state parameter mode.
2+
3+
!!! warning "Major"
4+
Maintainability
5+
6+
## Reason
7+
8+
By showing the mode of parameters, you help the reader. If you do not specify a parameter mode, the default mode is `IN`. Explicitly showing the mode indication of all parameters is a more assertive action than simply taking the default mode. Anyone reviewing the code later will be more confident that you intended the parameter mode to be `IN`, `OUT` or `IN OUT`.
9+
10+
## Example (bad)
11+
12+
```
13+
CREATE OR REPLACE PACKAGE employee_api IS
14+
PROCEDURE upsert (io_id IN OUT employees.id%TYPE
15+
,in_first_name employees.first_name%TYPE
16+
,in_last_name employees.last_name%TYPE
17+
,in_email employees.email%TYPE
18+
,in_department_id employees.department_id%TYPE
19+
,out_success OUT PLS_INTEGER);
20+
END employee_up;
21+
/
22+
```
23+
24+
## Example (good)
25+
26+
```
27+
CREATE OR REPLACE PACKAGE employee_api IS
28+
PROCEDURE upsert (io_id IN OUT employees.id%TYPE
29+
,in_first_name IN employees.first_name%TYPE
30+
,in_last_name IN employees.last_name%TYPE
31+
,in_email IN employees.email%TYPE
32+
,in_department_id IN employees.department_id%TYPE
33+
,out_success OUT PLS_INTEGER);
34+
END employee_up;
35+
/
36+
```

docs/4-language-usage/7-stored-objects/2-packages/g-7240.md renamed to docs/4-language-usage/7-stored-objects/1-general/g-7170.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# G-7240: Avoid using an IN OUT parameter as IN or OUT only.
1+
# G-7170: Avoid using an IN OUT parameter as IN or OUT only.
22

33
!!! warning "Major"
44
Efficiency, Maintainability
55

6+
!!! missing "Unsupported in PL/SQL Cop Validators"
7+
Rule G-7170 is not expected to be implemented in the static code analysis validators.
8+
69
## Reason
710

8-
By showing the mode of parameters, you help the reader. If you do not specify a parameter mode, the default mode is `IN`. Explicitly showing the mode indication of all parameters is a more assertive action than simply taking the default mode. Anyone reviewing the code later will be more confident that you intended the parameter mode to be `IN` / `OUT`.
11+
Avoid using parameter mode `IN OUT` unless you actually use the parameter both as input and output. If the code body only reads from the parameter, use `IN`; if the code body only assigns to the parameter, use `OUT`. If at the beginning of a project you expect a parameter to be both input and output and therefore choose `IN OUT` just in case, but later development shows the parameter actually is only `IN` or `OUT`, you should change the parameter mode accordingly.
912

1013
## Example (bad)
1114

1215
```
13-
-- Bad
1416
CREATE OR REPLACE PACKAGE BODY employee_up IS
1517
PROCEDURE rcv_emp (io_first_name IN OUT employees.first_name%TYPE
1618
,io_last_name IN OUT employees.last_name%TYPE
@@ -22,7 +24,7 @@ CREATE OR REPLACE PACKAGE BODY employee_up IS
2224
,io_commission_pct IN OUT employees.commission_pct%TYPE
2325
,io_manager_id IN OUT employees.manager_id%TYPE
2426
,io_department_id IN OUT employees.department_id%TYPE
25-
,in_wait INTEGER) IS
27+
,in_wait IN INTEGER) IS
2628
l_status PLS_INTEGER;
2729
co_dflt_pipe_name CONSTANT STRING(30 CHAR) := 'MyPipe';
2830
co_ok CONSTANT PLS_INTEGER := 1;
@@ -51,17 +53,17 @@ END employee_up;
5153

5254
```
5355
CREATE OR REPLACE PACKAGE BODY employee_up IS
54-
PROCEDURE rcv_emp (OUT_first_name OUT employees.first_name%TYPE
55-
,OUT_last_name OUT employees.last_name%TYPE
56-
,OUT_email OUT employees.email%TYPE
57-
,OUT_phone_number OUT employees.phone_number%TYPE
58-
,OUT_hire_date OUT employees.hire_date%TYPE
59-
,OUT_job_id OUT employees.job_id%TYPE
60-
,OUT_salary OUT employees.salary%TYPE
61-
,OUT_commission_pct OUT employees.commission_pct%TYPE
62-
,OUT_manager_id OUT employees.manager_id%TYPE
63-
,OUT_department_id OUT employees.department_id%TYPE
64-
,in_wait IN INTEGER) IS
56+
PROCEDURE rcv_emp (out_first_name OUT employees.first_name%TYPE
57+
,out_last_name OUT employees.last_name%TYPE
58+
,out_email OUT employees.email%TYPE
59+
,out_phone_number OUT employees.phone_number%TYPE
60+
,out_hire_date OUT employees.hire_date%TYPE
61+
,out_job_id OUT employees.job_id%TYPE
62+
,out_salary OUT employees.salary%TYPE
63+
,out_commission_pct OUT employees.commission_pct%TYPE
64+
,out_manager_id OUT employees.manager_id%TYPE
65+
,out_department_id OUT employees.department_id%TYPE
66+
,in_wait IN INTEGER) IS
6567
l_status PLS_INTEGER;
6668
co_dflt_pipe_name CONSTANT STRING(30 CHAR) := 'MyPipe';
6769
co_ok CONSTANT PLS_INTEGER := 1;

0 commit comments

Comments
 (0)