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 c8a5e86  add example for sql format and parameterize (#8729)
c8a5e86 is described below

commit c8a5e86b8e0742852061d37b21e8255c0ee09bb3
Author: JingShang Lu <[email protected]>
AuthorDate: Wed Dec 23 23:08:33 2020 +0800

    add example for sql format and parameterize (#8729)
    
    * add example for sql format and parameterize
---
 examples/Shardingsphere-parser-example/pom.xml     | 43 ++++++++++++++++++++++
 .../example/parser/SQLFormatExampleMain.java       | 38 +++++++++++++++++++
 .../parser/SQLParameterizedExampleMain.java        | 37 +++++++++++++++++++
 3 files changed, 118 insertions(+)

diff --git a/examples/Shardingsphere-parser-example/pom.xml 
b/examples/Shardingsphere-parser-example/pom.xml
new file mode 100644
index 0000000..3e08084
--- /dev/null
+++ b/examples/Shardingsphere-parser-example/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.shardingsphere.example</groupId>
+        <artifactId>shardingsphere-example</artifactId>
+        <version>5.0.0-alpha</version>
+    </parent>
+    <artifactId>shardingsphere-parser-example</artifactId>
+    <name>${project.artifactId}</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-sql-parser-engine</artifactId>
+            <version>5.0.0-RC1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-sql-parser-mysql</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/SQLFormatExampleMain.java
 
b/examples/Shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/SQLFormatExampleMain.java
new file mode 100644
index 0000000..83b4b5e
--- /dev/null
+++ 
b/examples/Shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/SQLFormatExampleMain.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+
+import java.util.Properties;
+
+public class SQLFormatExampleMain {
+
+    public static void main(String[] args) {
+        String sql = "select age as b, name n from table1 join table2 where 
id=1 and name='lu';";
+        Properties props = new Properties();
+        props.setProperty("parameterized", "false");
+        SQLParserEngine parserEngine = new SQLParserEngine("MySQL");
+        ParseTree tree = parserEngine.parse(sql, false);
+        SQLVisitorEngine visitorEngine = new SQLVisitorEngine("MySQL", 
"FORMAT", props);
+        String result = visitorEngine.visit(tree);
+        System.out.println(result);
+    }
+}
diff --git 
a/examples/Shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/SQLParameterizedExampleMain.java
 
b/examples/Shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/SQLParameterizedExampleMain.java
new file mode 100644
index 0000000..12a2503
--- /dev/null
+++ 
b/examples/Shardingsphere-parser-example/src/main/java/org/apache/shardingsphere/example/parser/SQLParameterizedExampleMain.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.shardingsphere.sql.parser.api.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.api.SQLVisitorEngine;
+
+import java.util.Properties;
+
+public class SQLParameterizedExampleMain {
+
+    public static void main(String[] args) {
+        String sql = "select age as b, name n from table1 join table2 where 
id=1 and name='lu';";
+        Properties props = new Properties();
+        SQLParserEngine parserEngine = new SQLParserEngine("MySQL");
+        ParseTree tree = parserEngine.parse(sql, false);
+        SQLVisitorEngine visitorEngine = new SQLVisitorEngine("MySQL", 
"FORMAT", props);
+        String result = visitorEngine.visit(tree);
+        System.out.println(result);
+    }
+}

Reply via email to