forked from phoedos/pmd
Support DeleteStatement
This commit is contained in:
parent
a3a48e2cb9
commit
a29fc094f9
@ -27,6 +27,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
/**
|
||||
* Added support for DELETE Statements
|
||||
*
|
||||
* Andreas Dangel 09/2018
|
||||
*====================================================================
|
||||
* Added support for OrderBy and RowLimiting clauses for SELECT statements
|
||||
* Removed FROM from the RelationalExpression
|
||||
* Support QueryPartitionClause
|
||||
@ -215,6 +219,7 @@ ASTInput Input() : {}
|
||||
| LOOKAHEAD(6) DDLCommand() //Ignore any other DDL Event
|
||||
| LOOKAHEAD(2) SqlPlusCommand()
|
||||
| LOOKAHEAD(2) UpdateStatement()
|
||||
| LOOKAHEAD(2) DeleteStatement()
|
||||
|(<SELECT>|<UPDATE>|<INSERT>|<DELETE>|<COMMIT>|<ROLLBACK>|<SAVEPOINT>|<LOCK><TABLE>|<MERGE>|<WITH>) SkipPastNextTokenOccurrence(SQLPLUS_TERMINATOR) //Ignore SQL statements in scripts
|
||||
)
|
||||
("/")*
|
||||
@ -1715,6 +1720,7 @@ ASTUnlabelledStatement UnlabelledStatement() :
|
||||
(
|
||||
SelectIntoStatement() ";" |
|
||||
UpdateStatement() ";" |
|
||||
DeleteStatement() ";" |
|
||||
LOOKAHEAD(["("] <SELECT>|<UPDATE>|<INSERT>|<DELETE>|<COMMIT>|<ROLLBACK>|<SAVEPOINT>|<EXECUTE>|<SET><TRANSACTION>|<LOCK><TABLE>|<MERGE>|<WITH>) SqlStatement(null,";") [";"]
|
||||
| LOOKAHEAD(3) ContinueStatement() ";" // CONTINUE keyword was added in 11G, so Oracle compilation supports CONTINUE as a variable name
|
||||
| CaseStatement() ";"
|
||||
@ -1852,6 +1858,15 @@ ASTUpdateSetClause UpdateSetClause() :
|
||||
{ return jjtThis; }
|
||||
}
|
||||
|
||||
ASTDeleteStatement DeleteStatement() :
|
||||
{}
|
||||
{
|
||||
<DELETE> [ <FROM> ]
|
||||
( TableReference() | <ONLY> "(" TableReference() ")" )
|
||||
[ WhereClause() ]
|
||||
{ return jjtThis; }
|
||||
}
|
||||
|
||||
/** Scope rule: the loop index only exists within the Loop */
|
||||
ASTForStatement ForStatement() :
|
||||
{}
|
||||
|
@ -936,4 +936,9 @@ public class PLSQLParserVisitorAdapter implements PLSQLParserVisitor {
|
||||
public Object visit(ASTUpdateSetClause node, Object data) {
|
||||
return visit((PLSQLNode) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDeleteStatement node, Object data) {
|
||||
return visit((PLSQLNode) node, data);
|
||||
}
|
||||
}
|
||||
|
@ -1030,6 +1030,11 @@ public abstract class AbstractPLSQLRule extends AbstractRule implements PLSQLPar
|
||||
return visit((PLSQLNode) node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDeleteStatement node, Object data) {
|
||||
return visit((PLSQLNode) node, data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Treat all Executable Code
|
||||
*/
|
||||
|
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.plsql.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.plsql.AbstractPLSQLParserTst;
|
||||
|
||||
public class DeleteStatementTest extends AbstractPLSQLParserTst {
|
||||
|
||||
@Test
|
||||
public void parseDeleteStatementExample() throws Exception {
|
||||
String code = IOUtils.toString(this.getClass().getResourceAsStream("DeleteStatementExample.pls"));
|
||||
ASTInput input = parsePLSQL(code);
|
||||
List<ASTDeleteStatement> deleteStatements = input.findDescendantsOfType(ASTDeleteStatement.class);
|
||||
Assert.assertEquals(3, deleteStatements.size());
|
||||
|
||||
Assert.assertEquals("product_descriptions", deleteStatements.get(0).jjtGetChild(0)
|
||||
.getFirstChildOfType(ASTTableName.class).getImage());
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
--
|
||||
-- Deleting Rows: Examples
|
||||
-- https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/DELETE.html#GUID-156845A5-B626-412B-9F95-8869B988ABD7
|
||||
--
|
||||
|
||||
DECLARE
|
||||
BEGIN
|
||||
|
||||
DELETE FROM product_descriptions
|
||||
WHERE language_id = 'AR';
|
||||
|
||||
DELETE FROM employees
|
||||
WHERE job_id = 'SA_REP'
|
||||
AND commission_pct < .2;
|
||||
|
||||
DELETE FROM (SELECT * FROM employees)
|
||||
WHERE job_id = 'SA_REP'
|
||||
AND commission_pct < .2;
|
||||
|
||||
END;
|
||||
/
|
Loading…
x
Reference in New Issue
Block a user