plsql:DecodeFunctionUsageCheck rule too strict

plsql
sonarqube
(Sebastien Guibert) #1

(My config : SonarQube: 6.7.6 , PL/SQL plugin 3.4.1 (build 2576))
Hi,
I had a doubt to open this here or in suggest new feature category.
As it concerns an enhancement (a kind of false-positive) of an existing rule and not a new rule, I open it here. Feel free to move if it is not the right place.

My remark concerns the detection of Decode usages.
I agree with the rule and prefer to use Case is most of the cases.

But when the decode has only one matching value and the default, for readability it is better to keep decode.

See below example:

SELECT
    emp.first_name                                    as first_name,
    emp.last_name                                     as last_name,
    DECODE(show_data_flag, 'Y', emp.salary, 'Hidden') as salary,
    DECODE(show_data_flag, 'Y', emp.bonus,  'Hidden') as bonus,
    ...
FROM employee
    ...

VS

SELECT
    emp.first_name                                  as first_name,
    emp.last_name                                   as last_name,
    CASE
        WHEN show_data_flag = 'Y' THEN emp.salary 
        ELSE 'Hidden' 
    END                                             as salary,
    CASE
        WHEN show_data_flag = 'Y' THEN emp.bonus
        ELSE 'Hidden' 
    END                                             as bonus,
    ...
FROM employee
    ...

Thanks in advance to take the time to evaluate this.
S.G.

(Sebastien Guibert) #3

No interest for my question ? :wink: