Package com.alibaba.druid.sql
Class SQLUtils
- java.lang.Object
-
- com.alibaba.druid.sql.SQLUtils
-
public class SQLUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSQLUtils.FormatOption
-
Field Summary
Fields Modifier and Type Field Description static SQLUtils.FormatOptionDEFAULT_FORMAT_OPTIONstatic SQLUtils.FormatOptionDEFAULT_LCASE_FORMAT_OPTION
-
Constructor Summary
Constructors Constructor Description SQLUtils()
-
Method Summary
-
-
-
Field Detail
-
DEFAULT_FORMAT_OPTION
public static SQLUtils.FormatOption DEFAULT_FORMAT_OPTION
-
DEFAULT_LCASE_FORMAT_OPTION
public static SQLUtils.FormatOption DEFAULT_LCASE_FORMAT_OPTION
-
-
Method Detail
-
toSQLString
public static String toSQLString(SQLObject sqlObject, DbType dbType, SQLUtils.FormatOption option)
-
toSQLString
public static String toSQLString(SQLObject sqlObject, DbType dbType, SQLUtils.FormatOption option, VisitorFeature... features)
-
toOdpsString
public static String toOdpsString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
toAntsparkString
public static String toAntsparkString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
toMySqlStringIfNotNull
public static String toMySqlStringIfNotNull(SQLObject sqlObject, String defaultStr)
-
toMySqlString
public static String toMySqlString(SQLObject sqlObject, VisitorFeature... features)
-
toMySqlString
public static String toMySqlString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
formatMySql
public static String formatMySql(String sql, SQLUtils.FormatOption option)
-
formatOracle
public static String formatOracle(String sql, SQLUtils.FormatOption option)
-
formatPresto
public static String formatPresto(String sql, SQLUtils.FormatOption option)
-
formatOdps
public static String formatOdps(String sql, SQLUtils.FormatOption option)
-
formatHive
public static String formatHive(String sql, SQLUtils.FormatOption option)
-
toOracleString
public static String toOracleString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
toPGString
public static String toPGString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
toDB2String
public static String toDB2String(SQLObject sqlObject, SQLUtils.FormatOption option)
-
toSQLServerString
public static String toSQLServerString(SQLObject sqlObject, SQLUtils.FormatOption option)
-
formatPGSql
public static String formatPGSql(String sql, SQLUtils.FormatOption option)
-
toSQLExpr
public static SQLExpr toSQLExpr(String sql, DbType dbType, SQLParserFeature... features)
-
toOrderByItem
public static SQLSelectOrderByItem toOrderByItem(String sql, DbType dbType)
-
toUpdateSetItem
public static SQLUpdateSetItem toUpdateSetItem(String sql, DbType dbType)
-
toSelectItem
public static SQLSelectItem toSelectItem(String sql, DbType dbType)
-
toStatementList
public static List<SQLStatement> toStatementList(String sql, DbType dbType)
-
format
public static String format(String sql, DbType dbType, SQLUtils.FormatOption option)
-
format
public static String format(String sql, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option)
-
format
public static String format(String sql, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option, SQLParserFeature[] features)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, SQLUtils.FormatOption option)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, SQLASTOutputVisitor visitor)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option, Map<String,String> tableMapping)
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters, Map<String,String> tableMapping, SQLASTOutputVisitor visitor)
-
createOutputVisitor
public static SQLASTOutputVisitor createOutputVisitor(StringBuilder out, DbType dbType)
-
createFormatOutputVisitor
public static SQLASTOutputVisitor createFormatOutputVisitor(StringBuilder out, List<SQLStatement> statementList, DbType dbType)
-
createSchemaStatVisitor
@Deprecated public static SchemaStatVisitor createSchemaStatVisitor(List<SQLStatement> statementList, DbType dbType)
Deprecated.
-
createSchemaStatVisitor
public static SchemaStatVisitor createSchemaStatVisitor(DbType dbType)
-
createSchemaStatVisitor
public static SchemaStatVisitor createSchemaStatVisitor(SchemaRepository repository)
-
createSchemaStatVisitor
public static SchemaStatVisitor createSchemaStatVisitor(SchemaRepository repository, DbType dbType)
-
parseStatements
public static List<SQLStatement> parseStatements(String sql, String dbType, SQLParserFeature... features)
-
parseStatements
public static List<SQLStatement> parseStatements(String sql, DbType dbType, SQLParserFeature... features)
-
parseStatements
public static List<SQLStatement> parseStatements(String sql, DbType dbType, boolean keepComments)
-
parseStatements
public static List<SQLStatement> parseStatements(String sql, String dbType)
-
parseStatements
public static List<SQLStatement> parseStatements(String sql, DbType dbType)
-
parseSingleStatement
public static SQLStatement parseSingleStatement(String sql, DbType dbType, boolean keepComments)
-
parseSingleStatement
public static SQLStatement parseSingleStatement(String sql, String dbType, SQLParserFeature... features)
-
parseSingleStatement
public static SQLStatement parseSingleStatement(String sql, DbType dbType, SQLParserFeature... features)
-
parseSingleMysqlStatement
public static SQLStatement parseSingleMysqlStatement(String sql)
-
buildToDate
public static String buildToDate(String columnName, String tableAlias, String pattern, DbType dbType)
- Parameters:
columnName-tableAlias-pattern- if pattern is null,it will be set {%Y-%m-%d %H:%i:%s} as mysql default value and set {yyyy-mm-dd hh24:mi:ss} as oracle default valuedbType-DbTypeif dbType is null ,it will be set the mysql as a default value
-
split
public static List<SQLExpr> split(SQLBinaryOpExpr x)
-
addCondition
public static String addCondition(String sql, String condition, SQLBinaryOperator op, boolean left, DbType dbType)
-
addCondition
public static void addCondition(SQLStatement stmt, SQLBinaryOperator op, SQLExpr condition, boolean left)
-
buildCondition
public static SQLExpr buildCondition(SQLBinaryOperator op, SQLExpr condition, boolean left, SQLExpr where)
-
addSelectItem
public static String addSelectItem(String selectSql, String expr, String alias, DbType dbType)
-
acceptBooleanOr
public static void acceptBooleanOr(String sql, DbType dbType, Consumer<SQLBinaryOpExprGroup> consumer)
-
acceptBinaryOpExprGroup
public static void acceptBinaryOpExprGroup(String sql, DbType dbType, Consumer<SQLBinaryOpExprGroup> consumer, Predicate<SQLBinaryOpExprGroup> filter)
-
acceptBinaryOpExpr
public static void acceptBinaryOpExpr(String sql, DbType dbType, Consumer<SQLBinaryOpExpr> consumer, Predicate<SQLBinaryOpExpr> filter)
-
acceptTableSource
public static void acceptTableSource(String sql, DbType dbType, Consumer<SQLTableSource> consumer, Predicate<SQLTableSource> filter)
-
acceptSelectQueryBlock
public static void acceptSelectQueryBlock(String sql, DbType dbType, Consumer<SQLSelectQueryBlock> consumer, Predicate<SQLSelectQueryBlock> filter)
-
acceptAggregateFunction
public static void acceptAggregateFunction(String sql, DbType dbType, Consumer<SQLAggregateExpr> consumer, Predicate<SQLAggregateExpr> filter)
-
acceptFunction
public static void acceptFunction(String sql, DbType dbType, Consumer<SQLMethodInvokeExpr> consumer, Predicate<SQLMethodInvokeExpr> filter)
-
acceptInsertInto
public static void acceptInsertInto(String sql, DbType dbType, Consumer<SQLInsertInto> consumer, Predicate<SQLInsertInto> filter)
-
addSelectItem
public static String addSelectItem(String selectSql, String expr, String alias, boolean first, DbType dbType)
-
addSelectItem
public static void addSelectItem(SQLStatement stmt, SQLExpr expr, String alias, boolean first)
-
addSelectItem
public static void addSelectItem(SQLSelectQueryBlock queryBlock, SQLExpr expr, String alias, boolean first)
-
refactor
public static String refactor(String sql, DbType dbType, Map<String,String> tableMapping)
-
isValue
public static boolean isValue(SQLExpr expr)
-
replaceInParent
public static boolean replaceInParent(SQLDataType expr, SQLDataType target)
-
replaceInParent
public static boolean replaceInParent(SQLTableSource cmp, SQLTableSource dest)
-
replaceInParent
public static boolean replaceInParent(SQLSelectQuery cmp, SQLSelectQuery dest)
-
replaceInParent
public static boolean replaceInParent(SQLStatement cmp, SQLStatement dest)
-
sort
public static String sort(String sql, DbType dbType)
重新排序建表语句,解决建表语句的依赖关系- Parameters:
sql-dbType-
-
clearLimit
public static Object[] clearLimit(String query, DbType dbType)
- Parameters:
query-dbType-- Returns:
- 0:sql.toString, 1:
-
getLimit
public static SQLLimit getLimit(SQLStatement statement, DbType dbType)
-
convertTimeZone
public static SQLStatement convertTimeZone(SQLStatement stmt, TimeZone from, TimeZone to)
-
splitInsertValues
public static List<SQLInsertStatement> splitInsertValues(DbType dbType, String insertSql, int size)
-
isQuoteChar
public static boolean isQuoteChar(char c)
-
-