mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql format support lcase
This commit is contained in:
@@ -133,10 +133,18 @@ public class SQLUtils {
|
||||
public static String formatMySql(String sql) {
|
||||
return format(sql, JdbcUtils.MYSQL);
|
||||
}
|
||||
|
||||
public static String formatMySql(String sql, FormatOption option) {
|
||||
return format(sql, JdbcUtils.MYSQL, option);
|
||||
}
|
||||
|
||||
public static String formatOracle(String sql) {
|
||||
return format(sql, JdbcUtils.ORACLE);
|
||||
}
|
||||
|
||||
public static String formatOracle(String sql, FormatOption option) {
|
||||
return format(sql, JdbcUtils.ORACLE, option);
|
||||
}
|
||||
|
||||
public static String formatOdps(String sql) {
|
||||
return format(sql, JdbcUtils.ODPS);
|
||||
@@ -151,8 +159,20 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
public static String toOracleString(SQLObject sqlObject) {
|
||||
return toOracleString(sqlObject, null);
|
||||
}
|
||||
|
||||
public static String toOracleString(SQLObject sqlObject, FormatOption option) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
sqlObject.accept(new OracleOutputVisitor(out, false));
|
||||
OracleOutputVisitor visitor = new OracleOutputVisitor(out, false);
|
||||
|
||||
if (option == null) {
|
||||
option = DEFAULT_FORMAT_OPTION;
|
||||
}
|
||||
|
||||
visitor.setUppCase(option.isUppCase());
|
||||
|
||||
sqlObject.accept(visitor);
|
||||
|
||||
String sql = out.toString();
|
||||
return sql;
|
||||
@@ -194,8 +214,8 @@ public class SQLUtils {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public static String formatPGSql(String sql) {
|
||||
return format(sql, JdbcUtils.POSTGRESQL);
|
||||
public static String formatPGSql(String sql, FormatOption option) {
|
||||
return format(sql, JdbcUtils.POSTGRESQL, option);
|
||||
}
|
||||
|
||||
public static SQLExpr toSQLExpr(String sql, String dbType) {
|
||||
|
||||
@@ -42,32 +42,32 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
|
||||
SQLOrderBy orderBy= ((SQLSelect) parent).getOrderBy();
|
||||
if (orderBy!=null&&orderBy.getItems().size() > 0) {
|
||||
println();
|
||||
print("ORDER BY ");
|
||||
print0(ucase ? "ORDER BY " : "order by ");
|
||||
printAndAccept(orderBy.getItems(), ", ");
|
||||
((SQLSelect) parent).setOrderBy(null);
|
||||
}
|
||||
}
|
||||
println();
|
||||
print("FETCH FIRST ");
|
||||
print0(ucase ? "FETCH FIRST " : "fetch first ");
|
||||
x.getFirst().accept(this);
|
||||
print(" ROWS ONLY");
|
||||
print0(ucase ? " ROWS ONLY" : " rows only");
|
||||
|
||||
|
||||
}
|
||||
if (x.isForReadOnly()) {
|
||||
println();
|
||||
print("FOR READ ONLY");
|
||||
print0(ucase ? "FOR READ ONLY" : "for read only");
|
||||
}
|
||||
|
||||
if (x.getIsolation() != null) {
|
||||
println();
|
||||
print("WITH ");
|
||||
print(x.getIsolation().name());
|
||||
print0(ucase ? "WITH " : "with ");
|
||||
print0(x.getIsolation().name());
|
||||
}
|
||||
|
||||
if (x.getOptimizeFor() != null) {
|
||||
println();
|
||||
print("OPTIMIZE FOR ");
|
||||
print0(ucase ? "OPTIMIZE FOR " : "optimize for ");
|
||||
x.getOptimizeFor().accept(this);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
|
||||
|
||||
@Override
|
||||
public boolean visit(DB2ValuesStatement x) {
|
||||
print("VALUES ");
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
x.getExpr().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-3
@@ -60,12 +60,12 @@ public class OracleSelectUnPivot extends OracleSelectPivotBase {
|
||||
public static enum NullsIncludeType {
|
||||
INCLUDE_NULLS, EXCLUDE_NULLS;
|
||||
|
||||
public static String toString(NullsIncludeType type) {
|
||||
public static String toString(NullsIncludeType type, boolean ucase) {
|
||||
if (INCLUDE_NULLS.equals(type)) {
|
||||
return "INCLUDE NULLS";
|
||||
return ucase ? "INCLUDE NULLS" : "include nulls";
|
||||
}
|
||||
if (EXCLUDE_NULLS.equals(type)) {
|
||||
return "EXCLUDE NULLS";
|
||||
return ucase ? "EXCLUDE NULLS" : "exclude nulls";
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
+481
-481
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -136,9 +136,9 @@ public class OracleToMySqlOutputVisitor extends OracleOutputVisitor {
|
||||
if (limit != null) {
|
||||
subSelect.accept(this);
|
||||
println();
|
||||
print("LIMIT ");
|
||||
print0(ucase ? "LIMIT " : "limit ");
|
||||
print(offset);
|
||||
print(", ");
|
||||
print0(", ");
|
||||
print(limit);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
if (x.getInto() != null) {
|
||||
println();
|
||||
if (x.getIntoOption() != null) {
|
||||
print(x.getIntoOption().name());
|
||||
print0(x.getIntoOption().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print0(ucase ? " AS " : " as ");
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
if (x.getUsing().size() > 0) {
|
||||
@@ -469,7 +469,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print0(ucase ? " AS " : " as ");
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
if (x.getParameters().size() > 0) {
|
||||
@@ -535,7 +535,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
@Override
|
||||
public boolean visit(PGExtractExpr x) {
|
||||
print0(ucase ? "EXTRACT (" : "extract (");
|
||||
print(x.getField().name());
|
||||
print0(x.getField().name());
|
||||
print0(ucase ? " FROM " : " from ");
|
||||
x.getSource().accept(this);
|
||||
print(')');
|
||||
@@ -653,7 +653,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
@Override
|
||||
public boolean visit(SQLBinaryExpr x) {
|
||||
print0(ucase ? "B'" : "b'");
|
||||
print(x.getValue());
|
||||
print0(x.getValue());
|
||||
print('\'');
|
||||
|
||||
return false;
|
||||
|
||||
+84
-84
@@ -53,14 +53,14 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
|
||||
public boolean visit(SQLServerSelectQueryBlock x) {
|
||||
print("SELECT ");
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
if (SQLSetQuantifier.ALL == x.getDistionOption()) {
|
||||
print("ALL ");
|
||||
print0(ucase ? "ALL " : "all ");
|
||||
} else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
|
||||
print("DISTINCT ");
|
||||
print0(ucase ? "DISTINCT " : "distinct ");
|
||||
} else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) {
|
||||
print("UNIQUE ");
|
||||
print0(ucase ? "UNIQUE " : "unique ");
|
||||
}
|
||||
|
||||
if (x.getTop() != null) {
|
||||
@@ -72,19 +72,19 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
if (x.getInto() != null) {
|
||||
println();
|
||||
print("INTO ");
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
x.getInto().accept(this);
|
||||
}
|
||||
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
print("FROM ");
|
||||
print0(ucase ? "FROM " : "from ");
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
@@ -104,23 +104,23 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerTop x) {
|
||||
print("TOP ");
|
||||
print0(ucase ? "TOP " : "top ");
|
||||
|
||||
boolean paren = false;
|
||||
|
||||
if (x.getParent() instanceof SQLServerUpdateStatement || x.getParent() instanceof SQLServerInsertStatement) {
|
||||
paren = true;
|
||||
print("(");
|
||||
print('(');
|
||||
}
|
||||
|
||||
x.getExpr().accept(this);
|
||||
|
||||
if (paren) {
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.isPercent()) {
|
||||
print(" PERCENT");
|
||||
print0(ucase ? " PERCENT" : " percent");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -133,7 +133,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerObjectReferenceExpr x) {
|
||||
print(x.toString());
|
||||
print0(x.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerInsertStatement x) {
|
||||
print("INSERT ");
|
||||
print0(ucase ? "INSERT " : "insert ");
|
||||
|
||||
if (x.getTop() != null) {
|
||||
x.getTop().setParent(x);
|
||||
@@ -152,25 +152,25 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
print(' ');
|
||||
}
|
||||
|
||||
print("INTO ");
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
incrementIndent();
|
||||
println();
|
||||
print("(");
|
||||
print('(');
|
||||
for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
if (i % 5 == 0) {
|
||||
println();
|
||||
}
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
|
||||
x.getColumns().get(i).accept(this);
|
||||
}
|
||||
print(")");
|
||||
print(')');
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
@@ -182,11 +182,11 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
if (x.getValuesList().size() != 0) {
|
||||
println();
|
||||
print("VALUES");
|
||||
print0(ucase ? "VALUES" : "values");
|
||||
println();
|
||||
for (int i = 0, size = x.getValuesList().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(",");
|
||||
print(',');
|
||||
println();
|
||||
}
|
||||
x.getValuesList().get(i).accept(this);
|
||||
@@ -199,7 +199,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
|
||||
if (x.isDefaultValues()) {
|
||||
print(" DEFAULT VALUES");
|
||||
print0(ucase ? " DEFAULT VALUES" : " default values");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerUpdateStatement x) {
|
||||
print("UPDATE ");
|
||||
print0(ucase ? "UPDATE " : "update ");
|
||||
|
||||
if (x.getTop() != null) {
|
||||
x.getTop().setParent(x);
|
||||
@@ -222,10 +222,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
println();
|
||||
print("SET ");
|
||||
print0(ucase ? "SET " : "set ");
|
||||
for (int i = 0, size = x.getItems().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
x.getItems().get(i).accept(this);
|
||||
}
|
||||
@@ -238,14 +238,14 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
print("FROM ");
|
||||
print0(ucase ? "FROM " : "from ");
|
||||
x.getFrom().setParent(x);
|
||||
x.getFrom().accept(this);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
println();
|
||||
print("WHERE ");
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
incrementIndent();
|
||||
x.getWhere().setParent(x);
|
||||
x.getWhere().accept(this);
|
||||
@@ -264,14 +264,14 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
x.getExpr().accept(this);
|
||||
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" WITH (");
|
||||
print0(ucase ? " WITH (" : " with (");
|
||||
printAndAccept(x.getHints(), ", ");
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(' ');
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -279,11 +279,11 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(Identity x) {
|
||||
print("IDENTITY (");
|
||||
print0(ucase ? "IDENTITY (" : "identity (");
|
||||
print(x.getSeed());
|
||||
print(", ");
|
||||
print0(", ");
|
||||
print(x.getIncrement());
|
||||
print(")");
|
||||
print(')');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
if (x.getEnable() != null) {
|
||||
if (x.getEnable().booleanValue()) {
|
||||
print(" ENABLE");
|
||||
print0(ucase ? " ENABLE" : " enable");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,12 +338,12 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerExecStatement x) {
|
||||
print("EXEC ");
|
||||
print0(ucase ? "EXEC " : "exec ");
|
||||
|
||||
SQLName returnStatus = x.getReturnStatus();
|
||||
if (returnStatus != null) {
|
||||
returnStatus.accept(this);
|
||||
print(" = ");
|
||||
print0(" = ");
|
||||
}
|
||||
|
||||
SQLName moduleName = x.getModuleName();
|
||||
@@ -351,7 +351,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
moduleName.accept(this);
|
||||
print(' ');
|
||||
} else {
|
||||
print(" (");
|
||||
print0(" (");
|
||||
}
|
||||
printAndAccept(x.getParameters(), ", ");
|
||||
|
||||
@@ -368,8 +368,8 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
print("SET TRANSACTION ISOLATION LEVEL ");
|
||||
print(x.getLevel());
|
||||
print0(ucase ? "SET TRANSACTION ISOLATION LEVEL " : "set transaction isolation level ");
|
||||
print0(x.getLevel());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -380,10 +380,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetStatement x) {
|
||||
print("SET ");
|
||||
print0(ucase ? "SET " : "set ");
|
||||
SQLAssignItem item = x.getItem();
|
||||
item.getTarget().accept(this);
|
||||
print(" ");
|
||||
print(' ');
|
||||
item.getValue().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -395,30 +395,30 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerOutput x) {
|
||||
print("OUTPUT ");
|
||||
print0(ucase ? "OUTPUT " : "output ");
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (x.getInto() != null) {
|
||||
incrementIndent();
|
||||
println();
|
||||
print("INTO ");
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
x.getInto().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
incrementIndent();
|
||||
println();
|
||||
print("(");
|
||||
print('(');
|
||||
for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
if (i % 5 == 0) {
|
||||
println();
|
||||
}
|
||||
print(", ");
|
||||
print0(", ");
|
||||
}
|
||||
|
||||
x.getColumns().get(i).accept(this);
|
||||
}
|
||||
print(")");
|
||||
print(')');
|
||||
decrementIndent();
|
||||
}
|
||||
}
|
||||
@@ -436,31 +436,31 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
x.getName().accept(this);
|
||||
|
||||
if(x.getType() == SQLServerDeclareItem.Type.TABLE) {
|
||||
print(" TABLE");
|
||||
print0(ucase ? " TABLE" : " table");
|
||||
int size = x.getTableElementList().size();
|
||||
|
||||
if (size > 0) {
|
||||
print(" (");
|
||||
print0(" (");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(",");
|
||||
print(',');
|
||||
println();
|
||||
}
|
||||
x.getTableElementList().get(i).accept(this);
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
print(')');
|
||||
}
|
||||
} else if (x.getType() == SQLServerDeclareItem.Type.CURSOR) {
|
||||
print(" CURSOR");
|
||||
print0(ucase ? " CURSOR" : " cursor");
|
||||
} else {
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getDataType().accept(this);
|
||||
if (x.getValue() != null) {
|
||||
print(" = ");
|
||||
print0(" = ");
|
||||
x.getValue().accept(this);
|
||||
}
|
||||
}
|
||||
@@ -475,7 +475,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
print("DECLARE ");
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
this.printAndAccept(x.getItems(), ", ");
|
||||
return false;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(Else x) {
|
||||
print("ELSE");
|
||||
print0(ucase ? "ELSE" : "else");
|
||||
incrementIndent();
|
||||
println();
|
||||
|
||||
@@ -511,7 +511,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerIfStatement x) {
|
||||
print("IF ");
|
||||
print0(ucase ? "IF " : "if ");
|
||||
x.getCondition().accept(this);
|
||||
incrementIndent();
|
||||
println();
|
||||
@@ -539,7 +539,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerBlockStatement x) {
|
||||
print("BEGIN");
|
||||
print0(ucase ? "BEGIN" : "begin");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0, size = x.getStatementList().size(); i < size; ++i) {
|
||||
@@ -549,11 +549,11 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
SQLStatement stmt = x.getStatementList().get(i);
|
||||
stmt.setParent(x);
|
||||
stmt.accept(this);
|
||||
print(";");
|
||||
print(';');
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print("END");
|
||||
print0(ucase ? "END" : "end");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -565,11 +565,11 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
@Override
|
||||
protected void printGrantOn(SQLGrantStatement x) {
|
||||
if (x.getOn() != null) {
|
||||
print(" ON ");
|
||||
print0(ucase ? " ON " : " on ");
|
||||
|
||||
if (x.getObjectType() != null) {
|
||||
print(x.getObjectType().name());
|
||||
print("::");
|
||||
print0(x.getObjectType().name());
|
||||
print0("::");
|
||||
}
|
||||
|
||||
x.getOn().accept(this);
|
||||
@@ -586,30 +586,30 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
super.visit(x);
|
||||
if (x.isForBrowse()) {
|
||||
println();
|
||||
print("FOR BROWSE");
|
||||
print0(ucase ? "FOR BROWSE" : "for browse");
|
||||
}
|
||||
|
||||
if (x.getForXmlOptions().size() > 0) {
|
||||
println();
|
||||
print("FOR XML ");
|
||||
print0(ucase ? "FOR XML " : "for xml ");
|
||||
for (int i = 0; i < x.getForXmlOptions().size(); ++i) {
|
||||
if (i != 0) {
|
||||
print(", ");
|
||||
print(x.getForXmlOptions().get(i));
|
||||
print0(", ");
|
||||
print0(x.getForXmlOptions().get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getOffset() != null) {
|
||||
println();
|
||||
print("OFFSET ");
|
||||
print0(ucase ? "OFFSET " : "offset ");
|
||||
x.getOffset().accept(this);
|
||||
print(" ROWS");
|
||||
print0(ucase ? " ROWS" : " rows");
|
||||
|
||||
if (x.getRowCount() != null) {
|
||||
print(" FETCH NEXT ");
|
||||
print0(ucase ? " FETCH NEXT " : " fetch next ");
|
||||
x.getRowCount().accept(this);
|
||||
print(" ROWS ONLY");
|
||||
print0(ucase ? " ROWS ONLY" : " rows only");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -617,20 +617,20 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerCommitStatement x) {
|
||||
print("COMMIT");
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
|
||||
if (x.isWork()) {
|
||||
print(" WORK");
|
||||
print0(ucase ? " WORK" : " work");
|
||||
} else {
|
||||
print(" TRANSACTION");
|
||||
print0(ucase ? " TRANSACTION" : " transaction");
|
||||
if (x.getTransactionName() != null) {
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getTransactionName().accept(this);
|
||||
}
|
||||
if (x.getDelayedDurability() != null) {
|
||||
print(" WITH ( DELAYED_DURABILITY = ");
|
||||
print0(ucase ? " WITH ( DELAYED_DURABILITY = " : " with ( delayed_durability = ");
|
||||
x.getDelayedDurability().accept(this);
|
||||
print(" )");
|
||||
print0(" )");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,14 +644,14 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
print("ROLLBACK");
|
||||
print0(ucase ? "ROLLBACK" : "rollback");
|
||||
|
||||
if (x.isWork()) {
|
||||
print(" WORK");
|
||||
print0(ucase ? " WORK" : " work");
|
||||
} else {
|
||||
print(" TRANSACTION");
|
||||
print0(ucase ? " TRANSACTION" : " transaction");
|
||||
if (x.getName() != null) {
|
||||
print(" ");
|
||||
print(' ');
|
||||
x.getName().accept(this);
|
||||
}
|
||||
}
|
||||
@@ -666,21 +666,21 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerWaitForStatement x) {
|
||||
print("WAITFOR");
|
||||
print0(ucase ? "WAITFOR" : "waitfor");
|
||||
|
||||
if (x.getDelay() != null) {
|
||||
print(" DELAY ");
|
||||
print0(ucase ? " DELAY " : " delay ");
|
||||
x.getDelay().accept(this);
|
||||
} else if (x.getTime() != null) {
|
||||
print(" TIME ");
|
||||
print0(ucase ? " TIME " : " time ");
|
||||
x.getTime().accept(this);
|
||||
} if (x.getStatement() != null) {
|
||||
print(" DELAY ");
|
||||
print0(ucase ? " DELAY " : " delay ");
|
||||
x.getStatement().accept(this);
|
||||
}
|
||||
|
||||
if(x.getTimeout() != null) {
|
||||
print(" ,TIMEOUT ");
|
||||
print0(ucase ? " ,TIMEOUT " : " ,timeout ");
|
||||
x.getTimeout().accept(this);
|
||||
}
|
||||
|
||||
@@ -698,7 +698,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
x.getExpr().accept(this);
|
||||
if(x.getType())
|
||||
{
|
||||
print(" OUT");
|
||||
print0(ucase ? " OUT" : " out");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,9 +116,9 @@ public class ParameterizedOutputVisitorUtils {
|
||||
x.getExpr().accept(v);
|
||||
|
||||
if (x.isNot()) {
|
||||
v.print(" NOT IN (?)");
|
||||
v.print(v.isUppCase() ? " NOT IN (?)" : " not in (?)");
|
||||
} else {
|
||||
v.print(" IN (?)");
|
||||
v.print(v.isUppCase() ? " IN (?)" : " in (?)");
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.visitor;
|
||||
|
||||
public interface PrintableVisitor extends SQLASTVisitor {
|
||||
boolean isUppCase();
|
||||
|
||||
void print(char value);
|
||||
|
||||
|
||||
@@ -520,7 +520,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLDataType x) {
|
||||
print(x.getName());
|
||||
print0(x.getName());
|
||||
if (x.getArguments().size() > 0) {
|
||||
print('(');
|
||||
printAndAccept(x.getArguments(), ", ");
|
||||
@@ -549,7 +549,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
print(x.getName());
|
||||
print0(x.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -612,15 +612,15 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
protected void printFunctionName(String name) {
|
||||
print(name);
|
||||
print0(name);
|
||||
}
|
||||
|
||||
public boolean visit(SQLAggregateExpr x) {
|
||||
print(x.getMethodName());
|
||||
print0(ucase ? x.getMethodName() : x.getMethodName().toLowerCase());
|
||||
print('(');
|
||||
|
||||
if (x.getOption() != null) {
|
||||
print(x.getOption().toString());
|
||||
print0(x.getOption().toString());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -657,7 +657,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? "NULL" : "null");
|
||||
} else {
|
||||
print0(ucase ? "N'" : "n'");
|
||||
print(x.getText().replace("'", "''"));
|
||||
print0(x.getText().replace("'", "''"));
|
||||
print('\'');
|
||||
}
|
||||
return false;
|
||||
@@ -816,10 +816,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
if (alias != null && alias.length() > 0) {
|
||||
print0(ucase ? " AS " : " as ");
|
||||
if (alias.indexOf(' ') == -1 || alias.charAt(0) == '"' || alias.charAt(0) == '\'') {
|
||||
print(alias);
|
||||
print0(alias);
|
||||
} else {
|
||||
print('"');
|
||||
print(alias);
|
||||
print0(alias);
|
||||
print('"');
|
||||
}
|
||||
}
|
||||
@@ -839,12 +839,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getExpr().accept(this);
|
||||
if (x.getType() != null) {
|
||||
print(' ');
|
||||
print(x.getType().name().toUpperCase());
|
||||
print0(x.getType().name().toUpperCase());
|
||||
}
|
||||
|
||||
if (x.getCollate() != null) {
|
||||
print0(ucase ? " COLLATE " : " collate ");
|
||||
print(x.getCollate());
|
||||
print0(x.getCollate());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -855,7 +855,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(' ');
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
if (isPrettyFormat() && x.hasAfterComment()) {
|
||||
@@ -878,7 +878,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
int index = x.getIndex();
|
||||
|
||||
if (parameters == null || index >= parameters.size()) {
|
||||
print(x.getName());
|
||||
print0(x.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -895,7 +895,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
if (param instanceof Number //
|
||||
|| param instanceof Boolean) {
|
||||
print(param.toString());
|
||||
print0(param.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1207,7 +1207,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLUnionQuery x) {
|
||||
x.getLeft().accept(this);
|
||||
println();
|
||||
print(x.getOperator().name);
|
||||
print0(x.getOperator().name);
|
||||
println();
|
||||
|
||||
boolean needParen = false;
|
||||
@@ -1234,7 +1234,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLUnaryExpr x) {
|
||||
print(x.getOperator().name);
|
||||
print0(x.getOperator().name);
|
||||
|
||||
SQLExpr expr = x.getExpr();
|
||||
|
||||
@@ -1266,7 +1266,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
@Override
|
||||
public boolean visit(SQLHexExpr x) {
|
||||
print0("0x");
|
||||
print(x.getHex());
|
||||
print0(x.getHex());
|
||||
|
||||
String charset = (String) x.getAttribute("USING");
|
||||
if (charset != null) {
|
||||
@@ -1349,7 +1349,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print0(ucase ? " AS " : " as ");
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
@@ -1452,7 +1452,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(' ');
|
||||
print(x.getAlias());
|
||||
print0(x.getAlias());
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1480,7 +1480,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLCommentStatement x) {
|
||||
print0(ucase ? "COMMENT ON " : "comment on ");
|
||||
if (x.getType() != null) {
|
||||
print(x.getType().name());
|
||||
print0(x.getType().name());
|
||||
print(' ');
|
||||
}
|
||||
x.getOn().accept(this);
|
||||
@@ -1806,14 +1806,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropConstraint x) {
|
||||
print(ucase ? "DROP CONSTRAINT " : "drop constraint ");
|
||||
print0(ucase ? "DROP CONSTRAINT " : "drop constraint ");
|
||||
x.getConstraintName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
print(ucase ? "ALTER TABLE " : "alter table ");
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
x.getName().accept(this);
|
||||
incrementIndent();
|
||||
for (int i = 0; i < x.getItems().size(); ++i) {
|
||||
@@ -1838,7 +1838,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLCreateIndexStatement x) {
|
||||
print0(ucase ? "CREATE " : "create ");
|
||||
if (x.getType() != null) {
|
||||
print(x.getType());
|
||||
print0(x.getType());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -2040,7 +2040,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? " ON " : " on ");
|
||||
|
||||
if (x.getObjectType() != null) {
|
||||
print(x.getObjectType().name());
|
||||
print0(x.getObjectType().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -2057,7 +2057,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? " ON " : " on ");
|
||||
|
||||
if (x.getObjectType() != null) {
|
||||
print(x.getObjectType().name());
|
||||
print0(x.getObjectType().name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -2128,7 +2128,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLAlterTableAddIndex x) {
|
||||
print0(ucase ? "ADD " : "add ");
|
||||
if (x.getType() != null) {
|
||||
print(x.getType());
|
||||
print0(x.getType());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -2136,7 +2136,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print0(ucase ? "UNIQUE " : "unique ");
|
||||
}
|
||||
|
||||
print(x.getKeyOrIndex());
|
||||
print0(x.getKeyOrIndex());
|
||||
print(' ');
|
||||
|
||||
if (x.getName() != null) {
|
||||
@@ -2149,7 +2149,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
if (x.getUsing() != null) {
|
||||
print0(ucase ? " USING " : " using ");
|
||||
print(x.getUsing());
|
||||
print0(x.getUsing());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2188,7 +2188,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
for (TriggerEvent event : x.getTriggerEvents()) {
|
||||
print(' ');
|
||||
print(event.name());
|
||||
print0(event.name());
|
||||
}
|
||||
println();
|
||||
print0(ucase ? "ON " : "on ");
|
||||
@@ -2205,7 +2205,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
public boolean visit(SQLBooleanExpr x) {
|
||||
print(x.getValue() ? "true" : "false");
|
||||
print0(x.getValue() ? "true" : "false");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -2240,12 +2240,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
}
|
||||
|
||||
print('\'');
|
||||
print(x.getLiteral());
|
||||
print0(x.getLiteral());
|
||||
print('\'');
|
||||
|
||||
if (x.getTimeZone() != null) {
|
||||
print0(ucase ? " AT TIME ZONE '" : " at time zone '");
|
||||
print(x.getTimeZone());
|
||||
print0(x.getTimeZone());
|
||||
print('\'');
|
||||
}
|
||||
|
||||
@@ -2255,7 +2255,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
@Override
|
||||
public boolean visit(SQLBinaryExpr x) {
|
||||
print0("b'");
|
||||
print(x.getValue());
|
||||
print0(x.getValue());
|
||||
print('\'');
|
||||
|
||||
return false;
|
||||
@@ -2346,7 +2346,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLAlterTableRenamePartition x) {
|
||||
print0(ucase ? "PARTITION (" : "partition (");
|
||||
printAndAccept(x.getPartition(), ", ");
|
||||
print(ucase ? ") RENAME TO PARTITION(" : ") rename to partition(");
|
||||
print0(ucase ? ") RENAME TO PARTITION(" : ") rename to partition(");
|
||||
printAndAccept(x.getTo(), ", ");
|
||||
print(')');
|
||||
return false;
|
||||
@@ -2414,7 +2414,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
@Override
|
||||
public boolean visit(SQLOpenStatement x) {
|
||||
print0(ucase ? "OPEN " : "open ");
|
||||
print(x.getCursorName());
|
||||
print0(x.getCursorName());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2430,7 +2430,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
@Override
|
||||
public boolean visit(SQLCloseStatement x) {
|
||||
print0(ucase ? "CLOSE " : "close ");
|
||||
print(x.getCursorName());
|
||||
print0(x.getCursorName());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user