sql format support lower case

This commit is contained in:
高铁
2015-12-12 20:54:02 +08:00
parent a84c53d4fb
commit de0715bd9c
11 changed files with 691 additions and 621 deletions
@@ -60,16 +60,16 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(WindowClause x) {
print("WINDOW ");
print0(ucase ? "WINDOW " : "window ");
x.getName().accept(this);
print(" AS ");
print0(ucase ? " AS " : " as ");
for (int i = 0; i < x.getDefinition().size(); ++i) {
if (i != 0) {
println(", ");
}
print("(");
print('(');
x.getDefinition().get(i).accept(this);
print(")");
print(')');
}
return false;
}
@@ -81,14 +81,14 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(FetchClause x) {
print("FETCH ");
print0(ucase ? "FETCH " : "fetch ");
if (FetchClause.Option.FIRST.equals(x.getOption())) {
print("FIRST ");
print0(ucase ? "FIRST " : "first ");
} else if (FetchClause.Option.NEXT.equals(x.getOption())) {
print("NEXT ");
print0(ucase ? "NEXT " : "next ");
}
x.getCount().accept(this);
print(" ROWS ONLY");
print0(ucase ? " ROWS ONLY" : " rows only");
return false;
}
@@ -99,11 +99,11 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(ForClause x) {
print("FOR ");
print0(ucase ? "FOR " : "for ");
if (ForClause.Option.UPDATE.equals(x.getOption())) {
print("UPDATE ");
print0(ucase ? "UPDATE " : "update ");
} else if (ForClause.Option.SHARE.equals(x.getOption())) {
print("SHARE ");
print0(ucase ? "SHARE " : "share ");
}
if (x.getOf().size() > 0) {
@@ -116,7 +116,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
}
if (x.isNoWait()) {
print(" NOWAIT");
print0(ucase ? " NOWAIT" : " nowait");
}
return false;
@@ -132,20 +132,20 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
x.getName().accept(this);
if (x.getColumns().size() > 0) {
print(" (");
print0(" (");
printAndAccept(x.getColumns(), ", ");
print(")");
print(')');
}
println();
print("AS");
print0(ucase ? "AS" : "as");
println();
print("(");
print('(');
incrementIndent();
println();
x.getQuery().accept(this);
decrementIndent();
println();
print(")");
print(')');
return false;
}
@@ -157,9 +157,9 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGWithClause x) {
print("WITH");
print0(ucase ? "WITH" : "with");
if (x.isRecursive()) {
print(" RECURSIVE ");
print0(ucase ? " RECURSIVE " : " recursive ");
}
incrementIndent();
println();
@@ -174,15 +174,15 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
println();
}
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 ");
if (x.getDistinctOn() != null && x.getDistinctOn().size() > 0) {
print("ON ");
print0(ucase ? "ON " : "on ");
printAndAccept(x.getDistinctOn(), ", ");
}
}
@@ -193,21 +193,22 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
println();
if (x.getIntoOption() != null) {
print(x.getIntoOption().name());
print(" ");
print(' ');
}
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);
}
@@ -229,7 +230,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
if (x.getLimit() != null) {
println();
print("LIMIT ");
print0(ucase ? "LIMIT " : "limit ");
x.getLimit().accept(this);
}
@@ -248,26 +249,26 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(SQLTruncateStatement x) {
print("TRUNCATE TABLE ");
print0(ucase ? "TRUNCATE TABLE " : "truncate table ");
if (x.isOnly()) {
print("ONLY ");
print0(ucase ? "ONLY " : "only ");
}
printlnAndAccept(x.getTableSources(), ", ");
if (x.getRestartIdentity() != null) {
if (x.getRestartIdentity().booleanValue()) {
print(" RESTART IDENTITY");
print0(ucase ? " RESTART IDENTITY" : " restart identity");
} else {
print(" CONTINUE IDENTITY");
print0(ucase ? " CONTINUE IDENTITY" : " continue identity");
}
}
if (x.getCascade() != null) {
if (x.getCascade().booleanValue()) {
print(" CASCADE");
print0(ucase ? " CASCADE" : " cascade");
} else {
print(" RESTRICT");
print0(ucase ? " RESTRICT" : " restrict");
}
}
return false;
@@ -285,28 +286,28 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
println();
}
print("DELETE FROM ");
print0(ucase ? "DELETE FROM " : "delete from ");
if (x.isOnly()) {
print("ONLY ");
print0(ucase ? "ONLY " : "only ");
}
x.getTableName().accept(this);
if (x.getAlias() != null) {
print(" AS ");
print0(ucase ? " AS " : " as ");
print(x.getAlias());
}
if (x.getUsing().size() > 0) {
println();
print("USING ");
print0(ucase ? "USING " : "using ");
printAndAccept(x.getUsing(), ", ");
}
if (x.getWhere() != null) {
println();
print("WHERE ");
print0(ucase ? "WHERE " : "where ");
incrementIndent();
x.getWhere().setParent(x);
x.getWhere().accept(this);
@@ -315,7 +316,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
if (x.isReturning()) {
println();
print("RETURNING *");
print0(ucase ? "RETURNING *" : "returning *");
}
return false;
@@ -333,30 +334,30 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
println();
}
print("INSERT INTO ");
print0(ucase ? "INSERT INTO " : "insert 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();
}
if (x.getValues() != null) {
println();
print("VALUES ");
print0(ucase ? "VALUES " : "values ");
printlnAndAccept(x.getValuesList(), ", ");
} else {
if (x.getQuery() != null) {
@@ -367,7 +368,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
if (x.getReturning() != null) {
println();
print("RETURNING ");
print0(ucase ? "RETURNING " : "returning ");
x.getReturning().accept(this);
}
@@ -401,32 +402,32 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
println();
}
print("UPDATE ");
print0(ucase ? "UPDATE " : "update ");
if (x.isOnly()) {
print("ONLY ");
print0(ucase ? "ONLY " : "only ");
}
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);
}
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 ");
incrementIndent();
x.getWhere().setParent(x);
x.getWhere().accept(this);
@@ -435,7 +436,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
if (x.getReturning().size() > 0) {
println();
print("RETURNING ");
print0(ucase ? "RETURNING " : "returning ");
printAndAccept(x.getReturning(), ", ");
}
@@ -455,7 +456,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGParameter x) {
x.getName().accept(this);
print(" ");
print(' ');
x.getDataType().accept(this);
@@ -467,7 +468,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
x.getExpr().accept(this);
if (x.getAlias() != null) {
print(" AS ");
print0(ucase ? " AS " : " as ");
print(x.getAlias());
}
@@ -489,7 +490,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
public boolean visit(PGLimit x) {
x.getRowCount().accept(this);
if (x.getOffset() != null) {
print(" OFFSET ");
print0(ucase ? " OFFSET " : " offset ");
x.getOffset().accept(this);
}
return false;
@@ -508,7 +509,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGTypeCastExpr x) {
x.getExpr().accept(this);
print("::");
print0("::");
x.getDataType().accept(this);
return false;
}
@@ -520,9 +521,9 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGValuesQuery x) {
print("VALUES(");
print0(ucase ? "VALUES(" : "values(");
printAndAccept(x.getValues(), ", ");
print(")");
print(')');
return false;
}
@@ -533,17 +534,17 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGExtractExpr x) {
print("EXTRACT (");
print0(ucase ? "EXTRACT (" : "extract (");
print(x.getField().name());
print(" FROM ");
print0(ucase ? " FROM " : " from ");
x.getSource().accept(this);
print(")");
print(')');
return false;
}
@Override
public boolean visit(PGBoxExpr x) {
print("BOX ");
print0(ucase ? "BOX " : "box ");
x.getValue().accept(this);
return false;
}
@@ -555,7 +556,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGPointExpr x) {
print("POINT ");
print0(ucase ? "POINT " : "point ");
x.getValue().accept(this);
return false;
}
@@ -567,7 +568,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGMacAddrExpr x) {
print("macaddr ");
print0("macaddr ");
x.getValue().accept(this);
return false;
}
@@ -579,7 +580,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGInetExpr x) {
print("inet ");
print0("inet ");
x.getValue().accept(this);
return false;
}
@@ -591,7 +592,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGCidrExpr x) {
print("cidr ");
print0("cidr ");
x.getValue().accept(this);
return false;
}
@@ -603,7 +604,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGPolygonExpr x) {
print("polygon ");
print0("polygon ");
x.getValue().accept(this);
return false;
}
@@ -615,7 +616,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGCircleExpr x) {
print("circle ");
print0("circle ");
x.getValue().accept(this);
return false;
}
@@ -627,7 +628,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGLineSegmentsExpr x) {
print("lseg ");
print0("lseg ");
x.getValue().accept(this);
return false;
}
@@ -639,7 +640,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGIntervalExpr x) {
print("INTERVAL ");
print0(ucase ? "INTERVAL " : "interval ");
x.getValue().accept(this);
return true;
}
@@ -651,7 +652,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(SQLBinaryExpr x) {
print("B'");
print0(ucase ? "B'" : "b'");
print(x.getValue());
print('\'');
@@ -665,7 +666,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
@Override
public boolean visit(PGShowStatement x) {
print("SHOW ");
print0(ucase ? "SHOW " : "show ");
x.getExpr().accept(this);
return false;
}