rspec/rules/S3481/cobol/rule.adoc

29 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Since databases don't offer "Are you sure?" dialogs, it's best to be very certain of what you're changing before you do it. ``++UPDATE++`` and ``++DELETE++`` statements that don't precisely limit their effects to single rows risk changing more than was intended. That's why they should be reviewed carefully.
This rule raises an issue when an ``++UPDATE++`` or ``++DELETE++`` statement's ``++WHERE++`` clause does not use precisely either a unique index or all parts of the table's primary key. That includes both cases where they are omitted in whole or in part, and when they are used but could still describe multiple rows. E.G. ``++WHERE AGE = 34++``, and ``++WHERE TABLE_ID > 0 AND TABLE_ID < 40++``.
*Note* That this rule raises issues only when a database catalog is provided during the SonarQube analysis.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
CREATE table my_table (
compound_a integer not null,
compound_b integer not null,
column_c varchar(50),
primary key (compound_a, compound_b)
);
DELETE FROM my_table
WHERE compound_b=4; -- Noncompliant
----
2021-04-28 16:49:39 +02:00
== Exceptions
Statements using a cursor and ``++WHERE CURRENT OF++`` are ignored.