Package com.alibaba.druid.sql
Class SQLUtils
java.lang.Object
com.alibaba.druid.sql.SQLUtils
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic SQLUtils.FormatOptionstatic SQLUtils.FormatOptionstatic final Charset -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidacceptAggregateFunction(String sql, DbType dbType, Consumer<SQLAggregateExpr> consumer, Predicate<SQLAggregateExpr> filter) static voidacceptBinaryOpExpr(String sql, DbType dbType, Consumer<SQLBinaryOpExpr> consumer, Predicate<SQLBinaryOpExpr> filter) static voidacceptBinaryOpExprGroup(String sql, DbType dbType, Consumer<SQLBinaryOpExprGroup> consumer, Predicate<SQLBinaryOpExprGroup> filter) static voidacceptBooleanOr(String sql, DbType dbType, Consumer<SQLBinaryOpExprGroup> consumer) static voidacceptFunction(String sql, DbType dbType, Consumer<SQLMethodInvokeExpr> consumer, Predicate<SQLMethodInvokeExpr> filter) static voidacceptInsertInto(String sql, DbType dbType, Consumer<SQLInsertInto> consumer, Predicate<SQLInsertInto> filter) static voidacceptSelectQueryBlock(String sql, DbType dbType, Consumer<SQLSelectQueryBlock> consumer, Predicate<SQLSelectQueryBlock> filter) static voidacceptTableSource(String sql, DbType dbType, Consumer<SQLTableSource> consumer, Predicate<SQLTableSource> filter) static voidaddCondition(SQLStatement stmt, SQLBinaryOperator op, SQLExpr condition, boolean left) static StringaddCondition(String sql, String condition, DbType dbType) static StringaddCondition(String sql, String condition, SQLBinaryOperator op, boolean left, DbType dbType) static voidaddSelectItem(SQLStatement stmt, SQLExpr expr, String alias, boolean first) static voidaddSelectItem(SQLSelectQueryBlock queryBlock, SQLExpr expr, String alias, boolean first) static StringaddSelectItem(String selectSql, String expr, String alias, boolean first, DbType dbType) static StringaddSelectItem(String selectSql, String expr, String alias, DbType dbType) static SQLExprbuildCondition(SQLBinaryOperator op, SQLExpr condition, boolean left, SQLExpr where) static StringbuildToDate(String columnName, String tableAlias, String pattern, DbType dbType) static Object[]clearLimit(String query, DbType dbType) static SQLStatementconvertTimeZone(SQLStatement stmt, TimeZone from, TimeZone to) static StringconvertTimeZone(String sql, TimeZone from, TimeZone to) static SQLASTOutputVisitorcreateFormatOutputVisitor(Appendable out, List<SQLStatement> statementList, DbType dbType) static SQLASTOutputVisitorcreateOutputVisitor(Appendable out, DbType dbType) static SchemaStatVisitorcreateSchemaStatVisitor(DbType dbType) static SchemaStatVisitorcreateSchemaStatVisitor(SchemaRepository repository) static SchemaStatVisitorcreateSchemaStatVisitor(SchemaRepository repository, DbType dbType) static SchemaStatVisitorcreateSchemaStatVisitor(List<SQLStatement> statementList, DbType dbType) Deprecated.static StringdesensitizeTable(String tableName) static StringforcedNormalize(String name, DbType dbType) static Stringstatic Stringformat(String sql, DbType dbType, SQLUtils.FormatOption option) static Stringstatic Stringstatic Stringformat(String sql, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option, SQLParserFeature[] features) static Stringstatic StringformatHive(String sql) static StringformatHive(String sql, SQLUtils.FormatOption option) static StringformatMySql(String sql) static StringformatMySql(String sql, SQLUtils.FormatOption option) static StringformatOdps(String sql) static StringformatOdps(String sql, SQLUtils.FormatOption option) static StringformatOracle(String sql) static StringformatOracle(String sql, SQLUtils.FormatOption option) static StringformatPGSql(String sql, SQLUtils.FormatOption option) static StringformatPresto(String sql) static StringformatPresto(String sql, SQLUtils.FormatOption option) static StringformatSQLServer(String sql) static SQLLimitgetLimit(SQLStatement statement, DbType dbType) static SQLLimitstatic longstatic booleanstatic booleannameEquals(SQLName a, SQLName b) static booleannameEquals(String a, String b) static Stringstatic Stringstatic Stringstatic SQLExprstatic SQLStatementstatic SQLStatementparseSingleStatement(String sql, DbType dbType, boolean keepComments) static SQLStatementparseSingleStatement(String sql, DbType dbType, SQLParserFeature... features) static SQLStatementparseSingleStatement(String sql, String dbType, SQLParserFeature... features) static List<SQLStatement>parseStatements(String sql, DbType dbType) static List<SQLStatement>parseStatements(String sql, DbType dbType, boolean keepComments) static List<SQLStatement>parseStatements(String sql, DbType dbType, SQLParserFeature... features) static List<SQLStatement>parseStatements(String sql, String dbType) static List<SQLStatement>parseStatements(String sql, String dbType, SQLParserFeature... features) static Stringstatic booleanreplaceInParent(SQLExpr expr, SQLExpr target) static booleanreplaceInParent(SQLSelectQuery cmp, SQLSelectQuery dest) static booleanreplaceInParent(SQLTableSource cmp, SQLTableSource dest) static String重新排序建表语句,解决建表语句的依赖关系static List<SQLInsertStatement>splitInsertValues(DbType dbType, String insertSql, int size) static StringtoAntsparkString(SQLObject sqlObject) static StringtoAntsparkString(SQLObject sqlObject, SQLUtils.FormatOption option) static StringtoDB2String(SQLObject sqlObject) static StringtoDB2String(SQLObject sqlObject, SQLUtils.FormatOption option) static StringtoHiveString(SQLObject sqlObject) static SQLExprtoMySqlExpr(String sql) static StringtoMySqlString(SQLObject sqlObject) static StringtoMySqlString(SQLObject sqlObject, SQLUtils.FormatOption option) static StringtoMySqlString(SQLObject sqlObject, VisitorFeature... features) static StringtoMySqlStringIfNotNull(SQLObject sqlObject, String defaultStr) static StringtoNormalizeMysqlString(SQLObject sqlObject) static StringtoOdpsString(SQLObject sqlObject) static StringtoOdpsString(SQLObject sqlObject, SQLUtils.FormatOption option) static StringtoOracleString(SQLObject sqlObject) static StringtoOracleString(SQLObject sqlObject, SQLUtils.FormatOption option) static SQLSelectOrderByItemtoOrderByItem(String sql, DbType dbType) static StringtoPGString(SQLObject sqlObject) static StringtoPGString(SQLObject sqlObject, SQLUtils.FormatOption option) static SQLSelectItemtoSelectItem(String sql, DbType dbType) static SQLExprstatic SQLExprstatic StringtoSQLServerString(SQLObject sqlObject) static StringtoSQLServerString(SQLObject sqlObject, SQLUtils.FormatOption option) static StringtoSQLString(SQLObject obj) static StringtoSQLString(SQLObject sqlObject, DbType dbType) static StringtoSQLString(SQLObject sqlObject, DbType dbType, SQLUtils.FormatOption option) static StringtoSQLString(SQLObject sqlObject, DbType dbType, SQLUtils.FormatOption option, VisitorFeature... features) static StringtoSQLString(SQLObject sqlObject, String dbType) static StringtoSQLString(List<SQLStatement> statementList, DbType dbType) static StringtoSQLString(List<SQLStatement> statementList, DbType dbType, SQLUtils.FormatOption option) static StringtoSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters) static StringtoSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option) static StringtoSQLString(List<SQLStatement> statementList, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option, Map<String, String> tableMapping) static List<SQLStatement>toStatementList(String sql, DbType dbType) static SQLUpdateSetItemtoUpdateSetItem(String sql, DbType dbType) static String
-
Field Details
-
UTF8
-
DEFAULT_FORMAT_OPTION
-
DEFAULT_LCASE_FORMAT_OPTION
-
-
Constructor Details
-
SQLUtils
public SQLUtils()
-
-
Method Details
-
toSQLString
-
toSQLString
-
toSQLString
-
toSQLString
public static String toSQLString(SQLObject sqlObject, DbType dbType, SQLUtils.FormatOption option, VisitorFeature... features) -
toSQLString
-
toOdpsString
-
toHiveString
-
toOdpsString
-
toAntsparkString
-
toAntsparkString
-
toMySqlString
-
toMySqlStringIfNotNull
-
toMySqlString
-
toNormalizeMysqlString
-
toMySqlString
-
toMySqlExpr
-
formatMySql
-
formatMySql
-
formatOracle
-
formatOracle
-
formatOdps
-
formatPresto
-
formatPresto
-
formatHive
-
formatOdps
-
formatHive
-
formatSQLServer
-
toOracleString
-
toOracleString
-
toPGString
-
toPGString
-
toDB2String
-
toDB2String
-
toSQLServerString
-
toSQLServerString
-
formatPGSql
-
toSQLExpr
-
toOrderByItem
-
toUpdateSetItem
-
toSelectItem
-
toStatementList
-
toSQLExpr
-
format
-
format
-
format
-
format
-
format
-
format
public static String format(String sql, DbType dbType, List<Object> parameters, SQLUtils.FormatOption option, SQLParserFeature[] features) -
toSQLString
-
toSQLString
public static String toSQLString(List<SQLStatement> statementList, DbType dbType, SQLUtils.FormatOption option) -
toSQLString
-
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, List<Object> parameters, SQLUtils.FormatOption option, Map<String, String> tableMapping) -
createOutputVisitor
-
createFormatOutputVisitor
public static SQLASTOutputVisitor createFormatOutputVisitor(Appendable out, List<SQLStatement> statementList, DbType dbType) -
createSchemaStatVisitor
@Deprecated public static SchemaStatVisitor createSchemaStatVisitor(List<SQLStatement> statementList, DbType dbType) Deprecated. -
createSchemaStatVisitor
-
createSchemaStatVisitor
-
createSchemaStatVisitor
-
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
-
parseStatements
-
parseStatements
-
parseSingleStatement
-
parseSingleStatement
public static SQLStatement parseSingleStatement(String sql, String dbType, SQLParserFeature... features) -
parseSingleStatement
public static SQLStatement parseSingleStatement(String sql, DbType dbType, SQLParserFeature... features) -
parseSingleMysqlStatement
-
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
-
translateOracleToMySql
-
addCondition
-
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
-
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
-
addSelectItem
-
addSelectItem
public static void addSelectItem(SQLSelectQueryBlock queryBlock, SQLExpr expr, String alias, boolean first) -
refactor
-
hash
-
not
-
normalize
-
normalize
-
normalize
-
forcedNormalize
-
nameEquals
-
nameEquals
-
isValue
-
replaceInParent
-
replaceInParent
-
replaceInParent
-
desensitizeTable
-
sort
重新排序建表语句,解决建表语句的依赖关系- Parameters:
sql-dbType-
-
clearLimit
- Parameters:
query-dbType-- Returns:
- 0:sql.toString, 1:
-
getLimit
-
getLimit
-
convertTimeZone
-
convertTimeZone
-
splitInsertValues
-