You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/12/11 07:39:44 UTC

[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #8575: add doc for sql format

jingshanglu commented on a change in pull request #8575:
URL: https://github.com/apache/shardingsphere/pull/8575#discussion_r540747674



##########
File path: docs/document/content/features/sharding/principle/parse.cn.md
##########
@@ -103,3 +103,108 @@ SQLVisitorEngine sqlVisitorEngine = new SQLVisitorEngine(databaseType, "STATEMEN
 SQLStatement sqlStatement = sqlVisitorEngine.visit(tree);
 
 ```
+
+- SQL格式化
+
+```
+/**
+ * databaseType type:String 可能值 MySQL
+ * useCache type:boolean 是否使用缓存
+ * @return String
+ */
+ParseTree tree = new SQLParserEngine(databaseType).parse(sql, useCache); 
+SQLVisitorEngine sqlVisitorEngine = new SQLVisitorEngine(databaseType, "FORMAT");
+String formatedSql = sqlVisitorEngine.visit(tree);
+
+//例子
+sql1 : select a+1 as b, name n from table1 join table2 where id=1 and name='lu';
+sql2 : select id, name, age, sex, ss, yy from table1 where id=1;
+sql3 : select id, name, age, count(*) as n, (select id, name, age, sex from table2 where id=2) as sid, yyyy from table1 where id=1;

Review comment:
       @tristaZero Ok.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org