Giter Club home page Giter Club logo

Comments (3)

mmarquezvacas avatar mmarquezvacas commented on May 23, 2024 1

@PhilippSalvisberg As always thanks a lot for your detailed help. I will communicate this to my team. Good to know we can also skip the false positive using --NOSONAR.
Thanks again for your great support.

from plsql-and-sql-coding-guidelines.

mmarquezvacas avatar mmarquezvacas commented on May 23, 2024

The same happens with TRUNC(); SUM() functions that are inside the SELECT statement

from plsql-and-sql-coding-guidelines.

PhilippSalvisberg avatar PhilippSalvisberg commented on May 23, 2024

Thanks @mmarquezvacas for reporting this issue.

I've opened an issue in our internal ticket system for PL/SQL. In this GitHub repository we handle just the guidelines. And this is not a guideline issue. Hence, I'm going to close this issue.

The issue is related to SYSDATE and not the EXTRACT, TRUNC or SUM function. SYSDATE is treated as a column. In the following example the line with current_month reports a G-3120 violation, but there is no violation for the line with hire_date_month.

SELECT emp.last_name
      ,emp.first_name
      ,dept.department_name
      ,EXTRACT(MONTH FROM emp.hire_date) AS hire_date_month
      ,EXTRACT(MONTH FROM SYSDATE) AS current_month
  FROM      employees   emp
       JOIN departments dept ON (emp.department_id = dept.department_id)
 WHERE EXTRACT(MONTH FROM emp.hire_date) = EXTRACT(MONTH FROM SYSDATE);

To fix the issue in the validator, we have to identify some pseudo columns and standalone functions. Since PL/SQL Cop relies on parsing only without semantic analysis (no database connection is required for the static code analysis) we cannot avoid false positives for user-defined functions or global variables. However, we can deal with common functions defined in the STANDARD package.

To answer your question. There is nothing you need to fix your code. If you want to suppress the false positive you have two options:

a) disable the check of the rule 3120 in the preferences dialog

image

b) disable the check for the line with the false positive

SELECT emp.last_name
      ,emp.first_name
      ,dept.department_name
      ,EXTRACT(MONTH FROM emp.hire_date) AS hire_date_month
      ,EXTRACT(MONTH FROM SYSDATE) AS current_month -- NOSONAR: G-3120 false positive
  FROM      employees   emp
       JOIN departments dept ON (emp.department_id = dept.department_id)
 WHERE EXTRACT(MONTH FROM emp.hire_date) = EXTRACT(MONTH FROM SYSDATE);

from plsql-and-sql-coding-guidelines.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.