Uploaded image for project: 'SonarPLSQL'
  1. SonarPLSQL
  2. SONARPLSQL-726

Improve DecodeFunctionUsageCheck: ignore when there is only 1 case

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.5
    • Component/s: Rules
    • Labels:
      None

      Description

      We should not report here as it is less readable than when using CASE

      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
          ...
      

      For reference, with CASE, it would reduce readability:

      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
          ...
      

      This change will require updating rule description.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              amelie.renard Amélie Renard
              Reporter:
              elena.vilchik Elena Vilchik
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: