This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 15629818f28 Support parsing MySQL stored procedure syntax - part 7 
(#38029)
15629818f28 is described below

commit 15629818f281f1a7aa94a36bf21070c0b0d52b73
Author: Claire <[email protected]>
AuthorDate: Sun Feb 15 14:18:19 2026 +0800

    Support parsing MySQL stored procedure syntax - part 7 (#38029)
    
    * support new statement
    
    * release-notes
    
    * update
    
    * release
---
 RELEASE-NOTES.md                                   |  3 +-
 .../statement/type/MySQLDDLStatementVisitor.java   | 10 ++++
 .../main/resources/case/ddl/create-procedure.xml   | 54 +++++++++++++++++++---
 .../sql/supported/ddl/create-procedure.xml         |  4 ++
 4 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 5a30efe17c9..8b7673b8e2d 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -52,7 +52,8 @@
 1. SQL Parser: Fix parsing error for SQLServer session `SET QUOTED_IDENTIFIER` 
and `SET TEXTSIZE` statements - 
[#38005](https://github.com/apache/shardingsphere/pull/38005)
 1. SQL Parser: Support '2'::int statement in PostgreSQL and openGauss - 
[#37962](https://github.com/apache/shardingsphere/pull/37962)
 1. SQL Parser: Support range type constructor functions in PostgreSQL without 
quotes - [#37994](https://github.com/apache/shardingsphere/pull/37994)
-1. SQL Parser: Support parsing MySQL stored procedure syntax - 
[#38017](https://github.com/apache/shardingsphere/pull/38017)
+1. SQL Parser: Support parsing MySQL stored procedure syntax part8- 
[#38017](https://github.com/apache/shardingsphere/pull/38017)
+1. SQL Parser: Support parsing MySQL stored procedure syntax part7- 
[#38029](https://github.com/apache/shardingsphere/pull/38029)
 1. SQL Binder: Support to bind more SQL statements - 
[#36697](https://github.com/apache/shardingsphere/pull/36697)
 1. SQL Binder: Add ALTER TABLE metadata check - 
[#35877](https://github.com/apache/shardingsphere/pull/35877)
 1. SQL Binder: Support Grant statement SQL bind - 
[#36207](https://github.com/apache/shardingsphere/pull/36207)
diff --git 
a/parser/sql/engine/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/engine/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
 
b/parser/sql/engine/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/engine/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
index 036cf59ed2c..27454412f46 100644
--- 
a/parser/sql/engine/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/engine/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
+++ 
b/parser/sql/engine/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/engine/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
@@ -192,6 +192,7 @@ import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.In
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.UpdateStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.DoStatement;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.StartTransactionStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.collection.CollectionValue;
 import 
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
 import 
org.apache.shardingsphere.sql.parser.statement.mysql.ddl.event.MySQLAlterEventStatement;
@@ -216,9 +217,12 @@ public final class MySQLDDLStatementVisitor extends 
MySQLStatementVisitor implem
     
     private final MySQLDALStatementVisitor dalStatementVisitor;
     
+    private final MySQLTCLStatementVisitor tclStatementVisitor;
+    
     public MySQLDDLStatementVisitor(final DatabaseType databaseType) {
         super(databaseType);
         dalStatementVisitor = new MySQLDALStatementVisitor(databaseType);
+        tclStatementVisitor = new MySQLTCLStatementVisitor(databaseType);
     }
     
     @Override
@@ -864,6 +868,12 @@ public final class MySQLDDLStatementVisitor extends 
MySQLStatementVisitor implem
             sqlStatement = (DeleteStatement) visit(ctx.delete());
         } else if (null != ctx.select()) {
             sqlStatement = (SelectStatement) visit(ctx.select());
+        } else if (null != ctx.startTransaction()) {
+            sqlStatement = new StartTransactionStatement(getDatabaseType());
+        } else if (null != ctx.commit()) {
+            sqlStatement = (SQLStatement) 
tclStatementVisitor.visitCommit(ctx.commit());
+        } else if (null != ctx.rollback()) {
+            sqlStatement = (SQLStatement) 
tclStatementVisitor.visitRollback(ctx.rollback());
         } else if (null != ctx.setVariable()) {
             sqlStatement = (SQLStatement) 
dalStatementVisitor.visitSetVariable(ctx.setVariable());
         } else if (null != ctx.doStatement()) {
diff --git a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml 
b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
index 2a03eb6dcb3..96562a8d460 100644
--- a/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
+++ b/test/it/parser/src/main/resources/case/ddl/create-procedure.xml
@@ -94,12 +94,12 @@
     <create-procedure sql-case-id="create_procedure_with_transaction">
         <procedure-name name="proc1" />
         <sql-statements>
-            <sql-statement start-index="30" stop-index="50" 
statement-class-simple-name="StartTransactionStatement" />
-            <sql-statement start-index="52" stop-index="83" 
statement-class-simple-name="CreateTableStatement" />
-            <sql-statement start-index="85" stop-index="93" 
statement-class-simple-name="RollbackStatement" />
-            <sql-statement start-index="95" stop-index="115" 
statement-class-simple-name="StartTransactionStatement" />
-            <sql-statement start-index="117" stop-index="148" 
statement-class-simple-name="CreateTableStatement" />
-            <sql-statement start-index="150" stop-index="158" 
statement-class-simple-name="CommitStatement" />
+            <sql-statement start-index="31" stop-index="48" 
statement-class-simple-name="StartTransactionStatement" />
+            <sql-statement start-index="50" stop-index="74" 
statement-class-simple-name="CreateTableStatement" />
+            <sql-statement start-index="76" stop-index="84" 
statement-class-simple-name="RollbackStatement" />
+            <sql-statement start-index="86" stop-index="103" 
statement-class-simple-name="StartTransactionStatement" />
+            <sql-statement start-index="105" stop-index="129" 
statement-class-simple-name="CreateTableStatement" />
+            <sql-statement start-index="131" stop-index="137" 
statement-class-simple-name="CommitStatement" />
         </sql-statements>
     </create-procedure>
     <create-procedure 
sql-case-id="create_procedure_with_charset_parameters_and_insert">
@@ -221,4 +221,46 @@
     <create-procedure sql-case-id="create_procedure_lib_uses_both">
         <procedure-name name="lib_uses_both" />
     </create-procedure>
+    <create-procedure sql-case-id="create_procedure_batch_insert">
+        <procedure-name name="BatchInsert" />
+        <sql-statements>
+            <sql-statement start-index="53" stop-index="70" 
statement-class-simple-name="StartTransactionStatement" />
+            <sql-statement start-index="72" stop-index="82" 
statement-class-simple-name="SetStatement" />
+            <sql-statement start-index="91" stop-index="136" 
statement-class-simple-name="SetStatement" />
+            <sql-statement start-index="138" stop-index="188" 
statement-class-simple-name="InsertStatement" />
+            <sql-statement start-index="190" stop-index="205" 
statement-class-simple-name="SetStatement" />
+            <sql-statement start-index="240" stop-index="246" 
statement-class-simple-name="CommitStatement" />
+        </sql-statements>
+    </create-procedure>
+    <create-procedure sql-case-id="create_procedure_p1_select_set">
+        <procedure-name name="p1" />
+        <sql-statements>
+            <sql-statement start-index="33" stop-index="56" 
statement-class-simple-name="SelectStatement" />
+            <sql-statement start-index="58" stop-index="74" 
statement-class-simple-name="SelectStatement" />
+            <sql-statement start-index="76" stop-index="86" 
statement-class-simple-name="SetStatement" />
+        </sql-statements>
+    </create-procedure>
+    <create-procedure sql-case-id="create_procedure_test_if_commit">
+        <procedure-name name="test_if_commit" />
+        <sql-statements>
+            <sql-statement start-index="40" stop-index="48" 
statement-class-simple-name="RollbackStatement" />
+            <sql-statement start-index="50" stop-index="119" 
statement-class-simple-name="SelectStatement" />
+            <sql-statement start-index="121" stop-index="138" 
statement-class-simple-name="DeleteStatement" />
+            <sql-statement start-index="140" stop-index="146" 
statement-class-simple-name="CommitStatement" />
+        </sql-statements>
+    </create-procedure>
+    <create-procedure sql-case-id="create_procedure_p1_repeat_handlers">
+        <procedure-name name="p1" />
+        <sql-statements>
+            <sql-statement start-index="169" stop-index="186" 
statement-class-simple-name="StartTransactionStatement" />
+            <sql-statement start-index="215" stop-index="297" 
statement-class-simple-name="SelectStatement" />
+            <sql-statement start-index="326" stop-index="400" 
statement-class-simple-name="SelectStatement" />
+            <sql-statement start-index="429" stop-index="460" 
statement-class-simple-name="InsertStatement" />
+            <sql-statement start-index="489" stop-index="520" 
statement-class-simple-name="InsertStatement" />
+            <sql-statement start-index="549" stop-index="563" 
statement-class-simple-name="DeleteStatement" />
+            <sql-statement start-index="592" stop-index="606" 
statement-class-simple-name="DeleteStatement" />
+            <sql-statement start-index="635" stop-index="641" 
statement-class-simple-name="CommitStatement" />
+            <sql-statement start-index="651" stop-index="676" 
statement-class-simple-name="SetStatement" />
+        </sql-statements>
+    </create-procedure>
 </sql-parser-test-cases>
diff --git 
a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml 
b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
index 5e8114e444f..df0e01b97ef 100644
--- a/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-procedure.xml
@@ -72,4 +72,8 @@
     <sql-case id="create_procedure_keywords_labeled_while" value="CREATE 
PROCEDURE p2() BEGIN DECLARE n INT DEFAULT 2; general: WHILE n &gt; 0 DO SET n 
= n -1; END WHILE general; SET n = 2; slow: WHILE n &gt; 0 DO SET n = n -1; END 
WHILE slow; SET n = 2; ignore_server_ids: WHILE n &gt; 0 DO SET n = n -1; END 
WHILE ignore_server_ids; SET n = 2; source_heartbeat_period: WHILE n &gt; 0 DO 
SET n = n -1; END WHILE source_heartbeat_period; END" db-types="MySQL" />
     <sql-case id="create_procedure_check_warnings" value="CREATE 
DEFINER=root@localhost PROCEDURE check_warnings(OUT result INT) BEGIN DECLARE 
`pos` bigint unsigned; SET SQL_LOG_BIN=0; UPDATE error_log el, 
global_suppressions gs SET suspicious=0 WHERE el.suspicious=1 AND el.line 
REGEXP gs.pattern; UPDATE error_log el, test_suppressions ts SET suspicious=0 
WHERE el.suspicious=1 AND el.line REGEXP ts.pattern; SELECT COUNT(*) INTO 
@num_warnings FROM error_log WHERE suspicious=1; IF @num_war [...]
     <sql-case id="create_procedure_lib_uses_both" value="CREATE PROCEDURE 
lib_uses_both() LANGUAGE JAVASCRIPT AS $$ console.log(&quot;Hello world&quot;) 
$$" db-types="MySQL" />
+    <sql-case id="create_procedure_batch_insert" value="CREATE PROCEDURE 
BatchInsert(IN row_count int) BEGIN START TRANSACTION; SET @n = 1; REPEAT SET 
@str = (CONCAT('test', CAST(@n AS CHAR))); INSERT INTO product(code, name) 
VALUES(@str, @str); SET @n = @n + 1; UNTIL @n &gt; row_count END REPEAT; 
COMMIT; END;" db-types="MySQL" />
+    <sql-case id="create_procedure_p1_select_set" value="CREATE PROCEDURE p1(x 
int) BEGIN SELECT count(*) FROM t1; SELECT * FROM t1; SET @x = x; END;" 
db-types="MySQL" />
+    <sql-case id="create_procedure_test_if_commit" value="CREATE PROCEDURE 
test_if_commit() BEGIN ROLLBACK; SELECT IF (COUNT(*) &gt; 0, &quot;YES&quot;, 
&quot;NO&quot;) AS &quot;IMPLICIT COMMIT&quot; FROM trans; DELETE FROM trans; 
COMMIT; END;" db-types="MySQL" />
+    <sql-case id="create_procedure_p1_repeat_handlers" value="create procedure 
p1() begin declare counter integer default 0; declare continue handler for 
sqlexception begin set counter = counter + 10;end; repeat if rand()&gt;0.5 then 
start transaction; end if; if rand()&gt;0.5 then select var_samp(1), 
exists(select 1 from t1 lock in share mode) from t1 into @a,@b; end if; if 
rand()&gt;0.5 then select var_samp(1), exists(select 1 from t1 for update) from 
t1 into @a,@b; end if; if rand()&g [...]
 </sql-cases>

Reply via email to