Skip to content

Commit 60166ce

Browse files
committed
Fix #54 - Added new rule G-2610: Never use self-defined weak ref cursor types.
1 parent 9a91155 commit 60166ce

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: Cursor Variables
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# G-2610: Never use self-defined weak ref cursor types.
2+
3+
!!! tip "Minor"
4+
Changeability, Maintainability, Portability, Reusability
5+
6+
## Reason
7+
8+
There is no reason to define your own weak ref cursor types, as they are not different from the built-in `sys_refcursor`. Introducing your own types just gives you unnecessary maintenance to perform.
9+
10+
## Example (bad)
11+
12+
``` sql
13+
declare
14+
type local_weak_cursor_type is ref cursor;
15+
cv_data local_weak_cursor_type;
16+
begin
17+
if configuration.use_employee then
18+
open cv_data for
19+
select e.employee_id, e.first_name, e.last_name
20+
from employees e;
21+
else
22+
open cv_data for
23+
select e.emp_id, e.name
24+
from emp e;
25+
end if;
26+
end;
27+
/
28+
```
29+
30+
## Example (good)
31+
32+
``` sql
33+
declare
34+
cv_data sys_refcursor;
35+
begin
36+
if configuration.use_employee then
37+
open cv_data for
38+
select e.employee_id, e.first_name, e.last_name
39+
from employees e;
40+
else
41+
open cv_data for
42+
select e.emp_id, e.name
43+
from emp e;
44+
end if;
45+
end;
46+
/
47+
```

docs/9-appendix/appendix.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ n/a | 2230 | Try to use SIMPLE_INTEGER datatype when appropriate. | Minor | |
4343
23 | 2340 | Always define your VARCHAR2 variables using CHAR SEMANTIC (if not defined anchored). | Minor | | | | | ✘ | | |
4444
24 | 2410 | Try to use boolean data type for values with dual meaning. | Minor | | | ✘ | | | | |
4545
25 | 2510 | Avoid using the LONG and LONG RAW data types. | Major | | | | ✘ | | | |
46+
n/a | 2610 | Never use self-defined weak ref cursor types. | Minor | ✘ | | ✘ | ✘ | | ✘ | |
4647
26 | 3110 | Always specify the target columns when coding an insert statement. | Major | | | ✘ | | ✘ | | |
4748
n/a | 3115 | Avoid self-assigning a column. | Minor | | | ✘ | | | | |
4849
27 | 3120 | Always use table aliases when your SQL statement involves more than one source. | Major | | | ✘ | | | | |
@@ -89,6 +90,7 @@ n/a | 5010 | Try to use a error/logging framework for your application. | Critic
8990
55 | 5050 | Avoid use of the RAISE_APPLICATION_ERROR built-in procedure with a hard-coded 20nnn error number or hard-coded message. | Major | ✘ | | ✘ | | | | |
9091
56 | 5060 | Avoid unhandled exceptions. | Major | | | | | ✘ | | |
9192
57 | 5070 | Avoid using Oracle predefined exceptions. | Critical | | | | | ✘ | | |
93+
n/a | 5080 | Always use FORMAT_ERROR_BACKTRACE when using FORMAT_ERROR_STACK or SQLERRM. | Minor | | | ✘ | | | | | ✘
9294
58 | 6010 | Always use a character variable to execute dynamic SQL. | Major | | | ✘ | | | | | ✘
9395
59 | 6020 | Try to use output bind arguments in the RETURNING INTO clause of dynamic DML statements rather than the USING clause. | Minor | | | ✘ | | | | |
9496
60 | 7110 | Try to use named notation when calling program units. | Major | ✘ | | ✘ | | | | |

docs/stylesheets/extra.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
[id="character-data-types"],
205205
[id="boolean-data-types"],
206206
[id="large-objects"],
207+
[id="cursor-variables"],
207208
[id="dml-sql"],
208209
[id="bulk-operations"],
209210
[id="transaction-control"],

tools/run-in-container/genpdf.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ write_text "### Boolean Data Types"
119119
write_guidelines "4-language-usage/2-variables-and-types/4-boolean-data-types" "####"
120120
write_text "### Large Objects"
121121
write_guidelines "4-language-usage/2-variables-and-types/5-large-objects" "####"
122+
write_text "### Cursor Variables"
123+
write_guidelines "4-language-usage/2-variables-and-types/6-cursor-variables" "####"
122124
write_text "## DML & SQL"
123125
write_text "### General"
124126
write_guidelines "4-language-usage/3-dml-and-sql/1-general" "####"

0 commit comments

Comments
 (0)