This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 45e327e Add examples to validate Parser SQLStatement for SqlServer
DataBase (#11300)
45e327e is described below
commit 45e327ef1966b0955a52ab527433987fe8071f49
Author: liguoping <[email protected]>
AuthorDate: Tue Jul 13 14:25:22 2021 +0800
Add examples to validate Parser SQLStatement for SqlServer DataBase (#11300)
* OracleParserStatementExample issue #11193
* SQLServerParserStatementExample issue #11195
---
examples/shardingsphere-parser-example/pom.xml | 5 ++
.../statement/SQLServerParserStatementExample.java | 63 ++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/examples/shardingsphere-parser-example/pom.xml
b/examples/shardingsphere-parser-example/pom.xml
index 8abc8c5..2686383 100644
--- a/examples/shardingsphere-parser-example/pom.xml
+++ b/examples/shardingsphere-parser-example/pom.xml
@@ -49,5 +49,10 @@
<artifactId>shardingsphere-sql-parser-sql92</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-sqlserver</artifactId>
+ <version>5.0.0-RC1-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
diff --git
a/examples/shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/sqlserver/statement/SQLServerParserStatementExample.java
b/examples/shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/sqlserver/statement/SQLServerParserStatementExample.java
new file mode 100644
index 0000000..35a7a03
--- /dev/null
+++
b/examples/shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/sqlserver/statement/SQLServerParserStatementExample.java
@@ -0,0 +1,63 @@
+/*
+ * 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.example.parser.sqlserver.statement;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+public final class SQLServerParserStatementExample {
+
+ private static final String DML_SELECT_SQL = "SELECT t.id, t.name, t.age
FROM table1 AS t ORDER BY t.id DESC;";
+
+ private static final String DML_INSERT_SQL = "INSERT INTO table1 (name,
age) VALUES ('z', 18);";
+
+ private static final String DML_UPDATE_SQL = "UPDATE table1 SET name = 'j'
WHERE id = 1;";
+
+ private static final String DML_DELETE_SQL = "DELETE FROM table1 AS t1
WHERE id = 1;";
+
+ private static final String DDL_CREATE_SQL = "CREATE TABLE table2 (id
BIGINT(20) PRIMARY KEY, name VARCHAR(20), age INT(2))";
+
+ private static final String DDL_DROP_SQL = "DROP TABLE table1, table2;";
+
+ private static final String DDL_ALTER_SQL = "ALTER TABLE table1 DROP age;";
+
+ private static final String DDL_TRUNCATE_SQL = "TRUNCATE TABLE table1;";
+
+ private static final List<String> SQLSERVER_PARSER_STATEMENT_LIST;
+
+ static {
+ SQLSERVER_PARSER_STATEMENT_LIST = Arrays.asList(DML_SELECT_SQL,
DML_INSERT_SQL, DML_UPDATE_SQL, DML_DELETE_SQL,
+ DDL_CREATE_SQL, DDL_DROP_SQL, DDL_ALTER_SQL, DDL_TRUNCATE_SQL);
+ }
+
+ public static void main(String[] args) {
+ SQLSERVER_PARSER_STATEMENT_LIST.forEach(sql -> {
+ SQLParserEngine parserEngine = new SQLParserEngine("SQLServer");
+ ParseTree tree = parserEngine.parse(sql, false);
+ SQLVisitorEngine visitorEngine = new SQLVisitorEngine("SQLServer",
"STATEMENT", new Properties());
+ SQLServerStatement sqlStatement = visitorEngine.visit(tree);
+ System.out.println(sqlStatement);
+ });
+ }
+}