Merge branch 'pr-1986'

This commit is contained in:
Andreas Dangel
2019-09-08 15:39:49 +02:00
5 changed files with 73 additions and 7 deletions

View File

@ -61,7 +61,9 @@ about the usage and features of the rule designer.
* [#1966](https://github.com/pmd/pmd/issues/1966): \[java] CloseResource false positive if Stream is passed as method parameter
* [#1967](https://github.com/pmd/pmd/issues/1967): \[java] CloseResource false positive with late assignment of variable
* plsql
* [#1933](https://github.com/pmd/pmd/issues/1933): \[plsql] ParseException with cursor declared in anonymous block
* [#1935](https://github.com/pmd/pmd/issues/1935): \[plsql] ParseException with SELECT INTO record defined as global variable
* [#1936](https://github.com/pmd/pmd/issues/1936): \[plslq] ParseException with cursor inside procedure declaration
* [#1946](https://github.com/pmd/pmd/issues/1946): \[plsql] ParseException with using TRIM inside IF statements condition
* [#1947](https://github.com/pmd/pmd/issues/1947): \[plsql] ParseError - SELECT with FOR UPDATE OF
* [#1948](https://github.com/pmd/pmd/issues/1948): \[plsql] ParseException with INSERT INTO using package global variables
@ -114,6 +116,7 @@ about the usage and features of the rule designer.
* [#1975](https://github.com/pmd/pmd/pull/1975): \[plsql] TRIM function with record type variables - [Piotr Szymanski](https://github.com/szyman23)
* [#1976](https://github.com/pmd/pmd/pull/1976): \[plsql] Fix for mistaking / for MultiplicativeExpression - [Piotr Szymanski](https://github.com/szyman23)
* [#1977](https://github.com/pmd/pmd/pull/1977): \[plsql] fix for skipping sql starting with WITH - [Piotr Szymanski](https://github.com/szyman23)
* [#1986](https://github.com/pmd/pmd/pull/1986): \[plsql] Fix for cursors in anonymous blocks - [Piotr Szymanski](https://github.com/szyman23)
* [#1994](https://github.com/pmd/pmd/pull/1994): \[core] Resolve pmd-report failure when java folder in filepath - [Amish Shah](https://github.com/shahamish150294)
{% endtocmaker %}

View File

@ -259,7 +259,7 @@ ASTInput Input(String sourcecode) : {}
| LOOKAHEAD(6) Directory()
| LOOKAHEAD(6) DatabaseLink()
| LOOKAHEAD(6) Global()
| LOOKAHEAD(6) DDLCommand() //Ignore any other DDL Event
| LOOKAHEAD(6) DDLCommand() //Ignore any other DDL Event
| LOOKAHEAD(2) SqlPlusCommand()
| UpdateStatement()
| DeleteStatement()
@ -359,21 +359,19 @@ ASTGlobal Global() :
{
}
{
/*
Remove triggers from global processing because their schema may be defined in the trigger code itself
Still wrap the trigger in a fake package but make the package name dependent on the actual schema
defaulting to the globalPackageName if it cannot be found
*/
(LOOKAHEAD ( ( Label() )* [<DECLARE> DeclarativeSection()] <BEGIN>) ( Label() )* Block() ";" | LOOKAHEAD (4) ProgramUnit()
(
LOOKAHEAD ( ( Label() )* ( <DECLARE> | <BEGIN> ) ) ( Label() )* Block() ";"
|
LOOKAHEAD (4) ProgramUnit()
)
{ return jjtThis ; }
}
ASTBlock Block() :
{
}

View File

@ -0,0 +1,32 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.plsql.ast;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import net.sourceforge.pmd.lang.plsql.AbstractPLSQLParserTst;
public class AnonymousBlockTest extends AbstractPLSQLParserTst {
@Test
public void parseCursorInsideProcAnonymousBlock() throws Exception {
String code = IOUtils.toString(this.getClass().getResourceAsStream("AnonymousBlock1.sql"),
StandardCharsets.UTF_8);
ASTInput input = parsePLSQL(code);
Assert.assertNotNull(input);
}
@Test
public void parseCursorInsideAnonymousBlock() throws Exception {
String code = IOUtils.toString(this.getClass().getResourceAsStream("AnonymousBlock2.sql"),
StandardCharsets.UTF_8);
ASTInput input = parsePLSQL(code);
Assert.assertNotNull(input);
}
}

View File

@ -0,0 +1,21 @@
declare
gw_acl_name varchar2(100);
procedure create_acl(p_acl_name in varchar2) is
cursor c_acl is
select dna.acl
from dba_network_acls dna
where acl like '%' || p_acl_name;
w_acl_name varchar2(100);
begin
open c_acl;
fetch c_acl
into w_acl_name;
close c_acl;
end;
begin
null;
end;
/

View File

@ -0,0 +1,12 @@
declare
cursor c_queue_exists(cp_queue_name xla_reference_code.code%type) is
select 1
from dba_queues dq
where dq.name = cp_queue_name;
r_queue_exists c_queue_exists%rowtype;
begin
null;
end;
/