You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/13 04:20:29 UTC

[shardingsphere] branch master updated: add SQLServer top clause for update statement. (#9410)

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

panjuan 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 4ebefff  add SQLServer top clause for update statement. (#9410)
4ebefff is described below

commit 4ebefffc50801106524b19758909fcfd05578e48
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Sat Feb 13 12:19:52 2021 +0800

    add SQLServer top clause for update statement. (#9410)
    
    * add SQLServer top clause for update statement.
    
    * add SQLServer test case for update top clause.
    
    Co-authored-by: Zonglei Dong <dz...@613.com>
---
 .../main/antlr4/imports/sqlserver/DMLStatement.g4  |  2 +-
 .../src/main/resources/case/dml/update.xml         | 58 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/update.xml    |  2 +
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
index a76e090..ca73773 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
@@ -36,7 +36,7 @@ insertSelectClause
     ;
 
 update
-    : withClause? UPDATE tableReferences setAssignmentsClause whereClause?
+    : withClause? UPDATE top? tableReferences setAssignmentsClause whereClause?
     ;
 
 assignment
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
index e4444e9..d7877c5 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/dml/update.xml
@@ -776,4 +776,62 @@
             </expr>
         </where>
     </update>
+
+    <update sql-case-id="update_with_top" parameters="1, 1">
+        <table start-index="15" stop-index="21">
+            <simple-table name="t_order" start-index="15" stop-index="21"/>
+        </table>
+        <set start-index="23" stop-index="38" literal-stop-index="38">
+            <assignment start-index="27" stop-index="38" literal-stop-index="38">
+                <column name="order_id" start-index="27" stop-index="34" />
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="38" stop-index="38" />
+                    <literal-expression value="1" start-index="38" stop-index="38" />
+                </assignment-value>
+            </assignment>
+        </set>
+        <where start-index="40" stop-index="56">
+            <expr>
+                <binary-operation-expression start-index="46" stop-index="56">
+                    <left>
+                        <column name="user_id" start-index="46" stop-index="52" />
+                    </left>
+                    <operator>=</operator>
+                    <right>
+                        <literal-expression value="1" start-index="56" stop-index="56" />
+                        <parameter-marker-expression value="1" start-index="56" stop-index="56" />
+                    </right>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </update>
+
+    <update sql-case-id="update_with_top_percent" parameters="1, 1">
+        <table start-index="23" stop-index="30">
+            <simple-table name="t_order" start-index="23" stop-index="29"/>
+        </table>
+        <set start-index="31" stop-index="46" literal-stop-index="46">
+            <assignment start-index="35" stop-index="46" literal-stop-index="46">
+                <column name="order_id" start-index="35" stop-index="42" />
+                <assignment-value>
+                    <parameter-marker-expression value="0" start-index="46" stop-index="46" />
+                    <literal-expression value="1" start-index="46" stop-index="46" />
+                </assignment-value>
+            </assignment>
+        </set>
+        <where start-index="48" stop-index="64">
+            <expr>
+                <binary-operation-expression start-index="54" stop-index="64">
+                    <left>
+                        <column name="user_id" start-index="54" stop-index="60" />
+                    </left>
+                    <operator>=</operator>
+                    <right>
+                        <literal-expression value="1" start-index="64" stop-index="64" />
+                        <parameter-marker-expression value="1" start-index="64" stop-index="64" />
+                    </right>
+                </binary-operation-expression>
+            </expr>
+        </where>
+    </update>
 </sql-parser-test-cases>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
index f3f2c31..a494dd7 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/dml/update.xml
@@ -34,4 +34,6 @@
     <sql-case id="update_with_order_by_row_count" value="UPDATE t_order SET status = ? WHERE order_id = ? AND user_id = ? ORDER BY order_id LIMIT ?" db-types="MySQL"/>
     <sql-case id="update_with_number" value="UPDATE t_order SET order_id = ? WHERE user_id = ?" db-types="PostgreSQL" />
     <sql-case id="update_with_with_clause" value="WITH cte (order_id, user_id, status) AS (SELECT order_id, user_id, status FROM t_order) UPDATE t_order SET status = ? FROM t_order AS t JOIN cte AS c ON t.order_id = c.order_id WHERE c.order_id = ?" db-types="SQLServer" />
+    <sql-case id="update_with_top" value="UPDATE TOP(10) t_order SET order_id = ? WHERE user_id = ?" db-types="SQLServer" />
+    <sql-case id="update_with_top_percent" value="UPDATE TOP(10) PERCENT t_order SET order_id = ? WHERE user_id = ?" db-types="SQLServer" />
 </sql-cases>