mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正输出格式
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@159 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -179,11 +179,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
if (select.getGroupBy() != null) {
|
||||
println();
|
||||
select.getGroupBy().accept(this);
|
||||
}
|
||||
|
||||
if (select.getOrderBy() != null) {
|
||||
print(" ");
|
||||
println();
|
||||
select.getOrderBy().accept(this);
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -2,10 +2,13 @@ package com.alibaba.druid.sql.dialect.mysql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
|
||||
|
||||
@@ -40,7 +43,7 @@ public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor {
|
||||
print(x.getRight().toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
x = merge(x);
|
||||
|
||||
return super.visit(x);
|
||||
@@ -92,6 +95,21 @@ public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLNumberExpr x) {
|
||||
print('?');
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
print('?');
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLNCharExpr x) {
|
||||
print('?');
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlInsertStatement x) {
|
||||
print("INSERT ");
|
||||
|
||||
+1
-1
@@ -667,7 +667,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
|
||||
if (select.getGroupBy() != null) {
|
||||
print(" ");
|
||||
println();
|
||||
select.getGroupBy().accept(this);
|
||||
}
|
||||
|
||||
|
||||
+47
@@ -1,9 +1,56 @@
|
||||
package com.alibaba.druid.sql.dialect.oracle.ast.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
|
||||
public class OracleParameterizedOutputVisitor extends OracleOutputVisitor {
|
||||
|
||||
public OracleParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public SQLBinaryOpExpr merge(SQLBinaryOpExpr x) {
|
||||
if (x.getRight() instanceof SQLLiteralExpr) {
|
||||
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), new SQLVariantRefExpr("?"));
|
||||
}
|
||||
|
||||
if (x.getLeft() instanceof SQLLiteralExpr) {
|
||||
x = new SQLBinaryOpExpr(new SQLVariantRefExpr("?"), x.getOperator(), x.getRight());
|
||||
}
|
||||
|
||||
if (x.getRight() instanceof SQLBinaryOpExpr) {
|
||||
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), merge((SQLBinaryOpExpr) x.getRight()));
|
||||
}
|
||||
|
||||
if (x.getLeft() instanceof SQLBinaryOpExpr) {
|
||||
x = new SQLBinaryOpExpr((SQLBinaryOpExpr) x.getLeft(), x.getOperator(), x.getRight());
|
||||
}
|
||||
|
||||
// ID = ? OR ID = ? => ID = ?
|
||||
if (x.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
if ((x.getLeft() instanceof SQLBinaryOpExpr) && (x.getRight() instanceof SQLBinaryOpExpr)) {
|
||||
SQLBinaryOpExpr left = (SQLBinaryOpExpr) x.getLeft();
|
||||
SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight();
|
||||
|
||||
if (left.getOperator() == SQLBinaryOperator.Equality && right.getOperator() == SQLBinaryOperator.Equality) {
|
||||
if ((left.getLeft() instanceof SQLIdentifierExpr) && (right.getLeft() instanceof SQLIdentifierExpr)) {
|
||||
String leftColumn = left.getLeft().toString();
|
||||
String rightColumn = right.getLeft().toString();
|
||||
|
||||
if (leftColumn.equals(rightColumn)) {
|
||||
if ((left.getRight() instanceof SQLVariantRefExpr) && (right.getRight() instanceof SQLVariantRefExpr)) {
|
||||
return left; // merge
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -641,7 +641,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
public final SQLExpr equality() throws ParserException {
|
||||
SQLExpr expr = multiplicative();
|
||||
SQLExpr expr = additive();
|
||||
return equalityRest(expr);
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
join.setCondition(expr());
|
||||
}
|
||||
|
||||
return join;
|
||||
return parseTableSourceRest(join);
|
||||
}
|
||||
|
||||
return tableSource;
|
||||
|
||||
@@ -389,7 +389,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public boolean visit(SQLSelectGroupByClause x) {
|
||||
if (x.getItems().size() > 0) {
|
||||
println();
|
||||
print("GROUP BY ");
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user