mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Updated Druid_SQL_AST (markdown)
+15
-1
@@ -179,5 +179,19 @@ String dbType = JdbcConstants.MYSQL;
|
||||
SQLExpr expr = SQLUtils.toSQLExpr("id=3", dbType);
|
||||
```
|
||||
|
||||
## 4. 如何遍历AST节点
|
||||
# 4. 怎样打印AST节点
|
||||
## 4.1通过SQLUtils工具类打印节点
|
||||
```java
|
||||
package com.alibaba.druid.sql;
|
||||
|
||||
public class SQLUtils {
|
||||
// 可以将SQLExpr/SQLStatement打印为String类型
|
||||
static String toSQLString(SQLObject sqlObj, String dbType);
|
||||
|
||||
// 可以将一个<SQLStatement>打印为String类型
|
||||
static String toSQLString(List<SQLStatement> statementList, String dbType);
|
||||
}
|
||||
```
|
||||
|
||||
# 5. 如何自定义遍历AST节点
|
||||
所有的AST节点都支持Visitor模式,需要自定义遍历逻辑,可以实现相应的ASTVisitorAdapter派生类,比如 https://github.com/alibaba/druid/wiki/SQL_Parser_Demo_visitor
|
||||
Reference in New Issue
Block a user