-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Druid_SQL_AST
高铁 edited this page Oct 3, 2017
·
26 revisions
AST是abstract syntax tree的缩写,也就是抽象语法树。和所有的Parser一样,Druid Parser会生成一个抽象语法树。
在Druid中,AST节点类型主要包括SQLObject、SQLExpr、SQLStatement三种抽象类型。
package com.alibaba.druid.sql.ast;
public interface SQLObject {}
public interface SQLExpr extends SQLObject {}
public interface SQLStatement {}
最常用的Statement当然是SELECT/UPDATE/DELETE/INSERT,他们分别是
package com.alibaba.druid.sql.ast.statement;
public class SQLSelectStatement {}
public class SQLUpdateStatement {}
public class SQLDeleteStatement {}
public class SQLInsertStatement {}
import com.alibaba.druid.util.JdbcConstants;
String dbType = JdbcConstants.MYSQL;
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType);
String dbType = JdbcConstants.MYSQL;
SQLExpr expr = SQLUtils.toSQLExpr("id=3", dbType);