Skip to content

Commit

Permalink
Support Mysql CALL sql with mysql prefix (#31133)
Browse files Browse the repository at this point in the history
  • Loading branch information
TherChenYang authored May 6, 2024
1 parent cf4a085 commit bd01cf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ querySpecification
;

call
: CALL identifier (LP_ (expr (COMMA_ expr)*)? RP_)?
: CALL (owner DOT_)? identifier (LP_ (expr (COMMA_ expr)*)? RP_)?
;

doStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public final class MySQLDMLStatementVisitor extends MySQLStatementVisitor implem
public ASTNode visitCall(final CallContext ctx) {
List<ExpressionSegment> params = new ArrayList<>();
ctx.expr().forEach(each -> params.add((ExpressionSegment) visit(each)));
return new MySQLCallStatement(ctx.identifier().getText(), params);
String procedureName = ctx.identifier().getText();
if (null != ctx.owner()) {
procedureName = ctx.owner().getText().concat(".").concat(procedureName);
}
return new MySQLCallStatement(procedureName, params);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions test/it/parser/src/main/resources/case/dml/call.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,14 @@
<common-expression literal-text="1.0/0.1" start-index="7" stop-index="13" />
</procedure-parameter>
</call>

<call sql-case-id="call_with_mysql_firewall_group_enlist">
<procedure-name name="mysql.sp_firewall_group_enlist"/>
<procedure-parameter>
<literal-expression value="fwgrp" start-index="36" stop-index="42"/>
</procedure-parameter>
<procedure-parameter>
<literal-expression value="member2@localhost" start-index="45" stop-index="63"/>
</procedure-parameter>
</call>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<sql-case id="call_with_mixed_notation_with_apos" value="CALL p(10, b =&gt; &apos;Hello&apos;);" db-types="PostgreSQL" />
<sql-case id="call_with_named_notation_with_apos" value="CALL p(b =&gt; &apos;Hello&apos;, a =&gt; 10);" db-types="PostgreSQL" />
<sql-case id="call_with_positional_notation_with_expression" value="CALL p(1.0/0.1);" db-types="PostgreSQL" />
<sql-case id="call_with_mysql_firewall_group_enlist" value="CALL mysql.sp_firewall_group_enlist('fwgrp', 'member2@localhost')" db-types="MySQL"/>
</sql-cases>

0 comments on commit bd01cf3

Please sign in to comment.