All Downloads are FREE. Search and download functionalities are using the official Maven repository.

category.plsql.errorprone.xml Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
<?xml version="1.0" encoding="UTF-8"?>

<ruleset name="Error Prone"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>
Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
    </description>

    <rule name="TO_DATE_TO_CHAR"
          language="plsql"
          since="5.1"
          message="TO_DATE(TO_CHAR(variable)) instead of TRUNC(variable)"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_plsql_errorprone.html#to_date_to_char">
        <description>
TO_DATE(TO_CHAR(date-variable)) used to remove time component - use TRUNC(date-variable)
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//FunctionCall[@Image='TO_DATE']
  [count(Arguments/ArgumentList/Argument) = 1]
  [Arguments/ArgumentList/Argument//FunctionCall[@Image='TO_CHAR']]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
CREATE OR REPLACE PACKAGE BODY date_utilities
IS

-- Take single parameter, relying on current default NLS date format
FUNCTION strip_time (p_date IN DATE) RETURN DATE
IS
BEGIN
   RETURN TO_DATE(TO_CHAR(p_date));
END strip_time;


END date_utilities;
/
]]>
        </example>
    </rule>

    <rule name="TO_DATEWithoutDateFormat"
          language="plsql"
          since="5.1"
          message="TO_DATE without date format"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_plsql_errorprone.html#to_datewithoutdateformat">
        <description>
TO_DATE without date format- use TO_DATE(expression, date-format)
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//FunctionCall[@Image='TO_DATE']
  [count(Arguments/ArgumentList/Argument) = 1]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
CREATE OR REPLACE PACKAGE BODY date_utilities
IS

-- Take single parameter, relying on current default NLS date format
FUNCTION to_date_single_parameter (p_date_string IN VARCHAR2) RETURN DATE
IS
BEGIN
   RETURN TO_DATE(p_date_string);
END to_date_single_parameter ;

-- Take 2 parameters, using an explicit date format string
FUNCTION to_date_two_parameters (p_date_string IN VARCHAR2, p_format_mask IN VARCHAR2) RETURN DATE
IS
BEGIN
   TO_DATE(p_date_string, p_date_format);
END to_date_two_parameters;

-- Take 3 parameters, using an explicit date format string and an explicit language
FUNCTION to_date_three_parameters (p_date_string IN VARCHAR2, p_format_mask IN VARCHAR2, p_nls_language VARCHAR2 ) RETURN DATE
IS
BEGIN
   TO_DATE(p_date_string, p_format_mask, p_nls_language);
END to_date_three_parameters;

END date_utilities;
/
]]>
        </example>
    </rule>

    <rule name="TO_TIMESTAMPWithoutDateFormat"
          language="plsql"
          message="TO_TIMESTAMP without date format"
          class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"
          since="5.1"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_plsql_errorprone.html#to_timestampwithoutdateformat">
        <description>
TO_TIMESTAMP without date format- use TO_TIMESTAMP(expression, date-format)
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//FunctionCall[@Image='TO_TIMESTAMP']
  [count(Arguments/ArgumentList/Argument) = 1]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
CREATE OR REPLACE PACKAGE BODY date_utilities
IS

-- Take single parameter, relying on current default NLS date format
FUNCTION to_timestamp_single_parameter (p_date_string IN VARCHAR2) RETURN DATE
IS
BEGIN
   RETURN TO_TIMESTAMP(p_date_string);
END to_timestamp_single_parameter;

-- Take 2 parameters, using an explicit date format string
FUNCTION to_timestamp_two_parameters (p_date_string IN VARCHAR2, p_format_mask IN VARCHAR2) RETURN DATE
IS
BEGIN
   TO_TIMESTAMP(p_date_string, p_date_format);
END to_timestamp_two_parameters;

-- Take 3 parameters, using an explicit date format string and an explicit language
FUNCTION to_timestamp_three_parameters (p_date_string IN VARCHAR2, p_format_mask IN VARCHAR2, p_nls_language VARCHAR2 ) RETURN DATE
IS
BEGIN
   TO_TIMESTAMP(p_date_string, p_format_mask, p_nls_language);
END to_timestamp_three_parameters;

END date_utilities;
/
]]>
        </example>
    </rule>

</ruleset>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy