mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser & support tableMapping. issue #1432
This commit is contained in:
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.DruidRuntimeException;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
@@ -263,10 +264,18 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
public static String toSQLString(List<SQLStatement> statementList, String dbType, List<Object> parameters) {
|
||||
return toSQLString(statementList, dbType, parameters, null);
|
||||
return toSQLString(statementList, dbType, parameters, null, null);
|
||||
}
|
||||
|
||||
public static String toSQLString(List<SQLStatement> statementList, String dbType, List<Object> parameters, FormatOption option) {
|
||||
return toSQLString(statementList, dbType, parameters, option, null);
|
||||
}
|
||||
|
||||
public static String toSQLString(List<SQLStatement> statementList
|
||||
, String dbType
|
||||
, List<Object> parameters
|
||||
, FormatOption option
|
||||
, Map<String, String> tableMapping) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = createFormatOutputVisitor(out, statementList, dbType);
|
||||
if (parameters != null) {
|
||||
@@ -278,6 +287,10 @@ public class SQLUtils {
|
||||
}
|
||||
visitor.setUppCase(option.isUppCase());
|
||||
|
||||
if (tableMapping != null) {
|
||||
visitor.setTableMapping(tableMapping);
|
||||
}
|
||||
|
||||
for (int i = 0; i < statementList.size(); i++) {
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
|
||||
@@ -645,5 +658,10 @@ public class SQLUtils {
|
||||
this.ucase = val;
|
||||
}
|
||||
}
|
||||
|
||||
public static String refactor(String dbType, String sql, Map<String, String> tableMapping) {
|
||||
List<SQLStatement> stmtList = parseStatements(sql, dbType);
|
||||
return SQLUtils.toSQLString(stmtList, dbType, null, null, tableMapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user