Menu

#1527 [plsql] PRAGMA AUTONOMOUS_TRANSACTION gives processing errors

PMD-5.3.8
closed
None
PMD
3-Major
Bug
5.x
2016-11-04
2016-09-26
No

This PLSQL code causes a Processing Error when running pmd.exe.

create or replace package inline_pragma_error is

end;
/

create or replace package body inline_pragma_error is
  procedure do_transaction(p_input_token        in varchar(200)) is

  begin
    PRAGMA AUTONOMOUS_TRANSACTION;
    bno74.log_hentglass_request(p_hentglass_request
                               ,v_logging_req_seq_no);
    COMMIT;
   end do_transaction;

end inline_pragma_error;
/

The debug output is below

C:\tia\gh\pmd-plsql-issue-pragma-inline>pmd -d . -f text -R ruleset.xml -debug
Counting for net.sourceforge.pmd.lang.plsql.ast.ExecutableCode
Counting for net.sourceforge.pmd.lang.plsql.ast.OracleObject
Loaded rule NPathComplexity
Loaded rule TooManyMethods
Loaded rule NcssObjectCount
Loaded rule TooManyFields
Loaded rule ExcessiveParameterList
Loaded rule NcssMethodCount
Loaded rule CyclomaticComplexity
Loaded rule ExcessiveTypeLength
Loaded rule ExcessivePackageSpecificationLength
Loaded rule ExcessiveObjectLength
Loaded rule ExcessiveMethodLength
Using PLSQL version: PLSQL
Counting for net.sourceforge.pmd.lang.plsql.ast.ExecutableCode
Counting for net.sourceforge.pmd.lang.plsql.ast.OracleObject
Loaded rule ExcessiveTypeLength
Loaded rule NcssObjectCount
Loaded rule NPathComplexity
Loaded rule ExcessiveParameterList
Loaded rule TooManyFields
Loaded rule CyclomaticComplexity
Loaded rule ExcessiveObjectLength
Loaded rule NcssMethodCount
Loaded rule TooManyMethods
Loaded rule ExcessivePackageSpecificationLength
Loaded rule ExcessiveMethodLength
Counting for net.sourceforge.pmd.lang.plsql.ast.ExecutableCode
Counting for net.sourceforge.pmd.lang.plsql.ast.OracleObject
Processing C:\tia\gh\pmd-plsql-issue-pragma-inline\InlinePragmaProcError.pls
Error while processing file: C:\tia\gh\pmd-plsql-issue-pragma-inline\InlinePragmaProcError.pls
net.sourceforge.pmd.lang.plsql.ast.ParseException: Encountered " "AUTONOMOUS_TRANSACTION" "AUTONOMOUS_TRANSACTION "" at line 10, column 12.
Was expecting:
    "INLINE" ...

        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.generateParseException(PLSQLParser.java:39942)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.jj_consume_token(PLSQLParser.java:39796)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.InlinePragma(PLSQLParser.java:21534)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.UnlabelledStatement(PLSQLParser.java:9439)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Statement(PLSQLParser.java:9974)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.ProgramUnit(PLSQLParser.java:5940)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.DeclarativeUnit(PLSQLParser.java:2087)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.DeclarativeSection(PLSQLParser.java:2505)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.PackageBody(PLSQLParser.java:1406)
        at net.sourceforge.pmd.lang.plsql.ast.PLSQLParser.Input(PLSQLParser.java:176)
        at net.sourceforge.pmd.lang.plsql.PLSQLParser.parse(PLSQLParser.java:47)
        at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:91)
        at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:138)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:76)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:43)
        at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78)
        at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:25)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

C:\tia\gh\pmd-plsql-issue-pragma-inline\InlinePragmaProcError.pls       -       Error while parsing C:\tia\gh\pmd-plsql-issue-pragma-inline\
InlinePragmaProcError.pls

The code works as expected on Oracle 11g and 12c.

2 Attachments

Related

Issues: #1539

Discussion

  • Andreas Markussen

    Oracle states that the PRAQMA AUTONOMOUS_TRANSACTION must be in the decleration box. but the code does not complain, when beeing compiled on the 11g DB
    https://docs.oracle.com/cd/B28359_01/appdev.111/b28370/static.htm#BABIIHBJ

    Following this advice helps, with the above code, but my developer will say. Oracle DB does not complain.

    I am new to PMD, so I dont mind fixing it my self, but I dont know how.

    Expected result would be that it recommends moving the PRAQMA AUTONOMOUS_TRANSACTION in to the decleration block as mentioned by oracle, however it should not give a processing error.

    create or replace package inline_pragma_ok is
    
    end;
    /
    
    create or replace package body inline_pragma_ok is
      procedure do_transaction(p_input_token        in varchar(200)) is
        PRAGMA AUTONOMOUS_TRANSACTION;
      begin
        bno74.log_hentglass_request(p_hentglass_request
                                   ,v_logging_req_seq_no);
        COMMIT;
       end do_transaction;
    
    end inline_pragma_ok;
    /
    

    The above code runs without issues.

     

    Last edit: Andreas Markussen 2016-09-26
  • Andreas Dangel

    Andreas Dangel - 2016-11-04

    I'll change the PLSQL grammar to allow the PRAGMA outside of a declaration block.
    Additionally, I'll create a new ruleset called "strictsyntax" which would create a rule violation, if this issue is encountered. See [#1539].

     

    Related

    Issues: #1539

  • Andreas Dangel

    Andreas Dangel - 2016-11-04
    • summary: PLSQL PRAGMA AUTONOMOUS_TRANSACTION gives processing errors --> [plsql] PRAGMA AUTONOMOUS_TRANSACTION gives processing errors
    • status: open --> in-progress
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.8
    • Ruleset / Rule: InlinePraqma ?? -->
     
  • Andreas Dangel

    Andreas Dangel - 2016-11-04
    • status: in-progress --> closed
     

Log in to post a comment.