From dbe3840db151f4fe8c483082f3a2d88f92ae9e2d Mon Sep 17 00:00:00 2001 From: Piotr Szymanski Date: Wed, 14 Aug 2019 14:28:13 +0200 Subject: [PATCH] fix for skipping sql starting with WITH --- pmd-plsql/etc/grammar/PldocAST.jjt | 3 ++- .../lang/plsql/ast/CursorWithWithTest.java | 24 +++++++++++++++++++ .../pmd/lang/plsql/ast/CursorWithWith.pls | 12 ++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/CursorWithWithTest.java create mode 100644 pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/CursorWithWith.pls diff --git a/pmd-plsql/etc/grammar/PldocAST.jjt b/pmd-plsql/etc/grammar/PldocAST.jjt index 6f3477722a..9d38e8f079 100644 --- a/pmd-plsql/etc/grammar/PldocAST.jjt +++ b/pmd-plsql/etc/grammar/PldocAST.jjt @@ -996,7 +996,8 @@ void Skip2NextTerminator(String initiator,String terminator) : t = getToken(1); if(t.image.equals(initiator)) count++; if(t.image.equals(terminator)) count--; - if((null != t.specialToken && beginToken.kind != SELECT && beginToken.kind != INSERT && beginToken.kind != UPDATE && beginToken.kind != DELETE && beginToken.kind != MERGE && beginToken.kind != EXECUTE) || t.kind == EOF) + if((null != t.specialToken && beginToken.kind != SELECT && beginToken.kind != INSERT && beginToken.kind != UPDATE && beginToken.kind != DELETE + && beginToken.kind != MERGE && beginToken.kind != EXECUTE && beginToken.kind != WITH) || t.kind == EOF) return; if (t.specialToken != null && "/".equals(t.image)) return; diff --git a/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/CursorWithWithTest.java b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/CursorWithWithTest.java new file mode 100644 index 0000000000..147636cd12 --- /dev/null +++ b/pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/CursorWithWithTest.java @@ -0,0 +1,24 @@ +/** + * 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 CursorWithWithTest extends AbstractPLSQLParserTst { + + @Test + public void parseCursorWithWith() throws Exception { + String code = IOUtils.toString(this.getClass().getResourceAsStream("CursorWithWith.pls"), + StandardCharsets.UTF_8); + ASTInput input = parsePLSQL(code); + Assert.assertNotNull(input); + } +} diff --git a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/CursorWithWith.pls b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/CursorWithWith.pls new file mode 100644 index 0000000000..6f07089372 --- /dev/null +++ b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/ast/CursorWithWith.pls @@ -0,0 +1,12 @@ +create or replace procedure test is + + cursor c_tariff_price is + with risk_set as + (select 2 from + dual) + select 1 from dual; + +begin + null; +end; +/ \ No newline at end of file