Skip to content

Commit

Permalink
[Parser Oracle] Support Create Trigger Statement (#29604)
Browse files Browse the repository at this point in the history
* 27119 Support Create Trigger Parser in Oracle

format the code

format the code

* Move Create Trigger Statement into PLSQL.g4
  • Loading branch information
ilyasahsan123 authored Dec 31, 2023
1 parent c465a15 commit 299f5e5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions parser/sql/dialect/oracle/src/main/antlr4/imports/oracle/PLSQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ createFunction
: CREATE (OR REPLACE)? (EDITIONABLE | NONEDITIONABLE)? FUNCTION plsqlFunctionSource
;

createTrigger
: CREATE (OR REPLACE)? TRIGGER triggerName (BEFORE | AFTER | INSTEAD OF) dmlEventClause
;

plsqlFunctionSource
: function (LP_ parameterDeclaration (COMMA_ parameterDeclaration)* RP_)? RETURN dataType
sharingClause? (invokerRightsClause
Expand Down Expand Up @@ -274,3 +278,11 @@ pragma
autonomousTransPragma
: PRAGMA AUTONOMOUS_TRANSACTION SEMI_
;

dmlEventClause
: dmlEventElement (OR dmlEventElement)* ON viewName
;

dmlEventElement
: (DELETE | INSERT | UPDATE) (OF LP_ columnName (COMMA_ columnName)* RP_)?
;
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,6 @@ execute
| createLibrary
| switch
| createProfile
| createTrigger
) SEMI_?
;
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateSynonymContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTableContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTablespaceContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTriggerContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateTypeContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CreateViewContext;
import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.DataTypeDefinitionContext;
Expand Down Expand Up @@ -269,6 +270,7 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateSynonymStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTablespaceStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateTriggerStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateVarrayTypeStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateViewStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleDisassociateStatisticsStatement;
Expand Down Expand Up @@ -762,6 +764,11 @@ public ASTNode visitDropTrigger(final DropTriggerContext ctx) {
return new OracleDropTriggerStatement();
}

@Override
public ASTNode visitCreateTrigger(final CreateTriggerContext ctx) {
return new OracleCreateTriggerStatement();
}

@Override
public ASTNode visitAlterTrigger(final AlterTriggerContext ctx) {
return new OracleAlterTriggerStatement();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl;

import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTriggerStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.OracleStatement;

/**
* Oracle create trigger statement.
*/
public final class OracleCreateTriggerStatement extends CreateTriggerStatement implements OracleStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
<!-- <create-trigger sql-case-id="create_trigger_with_when" />-->
<!-- <create-trigger sql-case-id="create_trigger_after_update" />-->
<create-trigger sql-case-id="create_trigger_with_create_view" />
<create-trigger sql-case-id="create_trigger_with_dml_event_clause" />
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
SELECT EVENTDATA()" db-types="SQLServer" />

<sql-case id="create_trigger_with_create_view" value="CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END" db-types="MySQL" />
<sql-case id="create_trigger_with_dml_event_clause" value="CREATE TRIGGER scott.emp_permit_changes BEFORE DELETE OR INSERT OR UPDATE ON scott.emp" db-types="Oracle" />
</sql-cases>

0 comments on commit 299f5e5

Please sign in to comment.