mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -19,7 +19,7 @@ public final class VERSION {
|
||||
|
||||
public final static int MajorVersion = 1;
|
||||
public final static int MinorVersion = 1;
|
||||
public final static int RevisionVersion = 5;
|
||||
public final static int RevisionVersion = 6;
|
||||
|
||||
public static String getVersionNumber() {
|
||||
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion;
|
||||
|
||||
@@ -644,35 +644,19 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
}
|
||||
|
||||
String varName = x.getName();
|
||||
if (x.isGlobal()) {
|
||||
print0("@@global.");
|
||||
} else {
|
||||
// if ((!varName.startsWith("@")) // /
|
||||
// && (!varName.equals("?")) //
|
||||
// && (!varName.startsWith("#")) //
|
||||
// && (!varName.startsWith("$")) //
|
||||
// && (!varName.startsWith(":"))) {
|
||||
//
|
||||
// boolean subPartitionOption = false;
|
||||
// if (x.getParent() != null) {
|
||||
// subPartitionOption = x.getParent().getParent() instanceof SQLSubPartitionBy;
|
||||
// }
|
||||
//
|
||||
// if (!subPartitionOption) {
|
||||
// print0("@@");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
for (int i = 0; i < x.getName().length(); ++i) {
|
||||
char ch = x.getName().charAt(i);
|
||||
String varName = x.getName();
|
||||
for (int i = 0; i < varName.length(); ++i) {
|
||||
char ch = varName.charAt(i);
|
||||
if (ch == '\'') {
|
||||
if (x.getName().startsWith("@@") && i == 2) {
|
||||
if (varName.startsWith("@@") && i == 2) {
|
||||
print(ch);
|
||||
} else if (x.getName().startsWith("@") && i == 1) {
|
||||
} else if (varName.startsWith("@") && i == 1) {
|
||||
print(ch);
|
||||
} else if (i != 0 && i != x.getName().length() - 1) {
|
||||
} else if (i != 0 && i != varName.length() - 1) {
|
||||
print0("\\'");
|
||||
} else {
|
||||
print(ch);
|
||||
@@ -2462,38 +2446,6 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
}
|
||||
|
||||
// public boolean visit(SQLUnionQuery x) {
|
||||
// print('(');
|
||||
// x.getLeft().accept(this);
|
||||
// print(')');
|
||||
// println();
|
||||
// print0(ucase ? x.getOperator().name : x.getOperator().name_lcase);
|
||||
// println();
|
||||
//
|
||||
// SQLSelectQuery right = x.getRight();
|
||||
// boolean needParen = ! (right instanceof SQLUnionQuery);
|
||||
//
|
||||
// if (needParen) {
|
||||
// print('(');
|
||||
// right.accept(this);
|
||||
// print(')');
|
||||
// } else {
|
||||
// right.accept(this);
|
||||
// }
|
||||
//
|
||||
// if (x.getOrderBy() != null) {
|
||||
// println();
|
||||
// x.getOrderBy().accept(this);
|
||||
// }
|
||||
//
|
||||
// if (x.getLimit() != null) {
|
||||
// println();
|
||||
// x.getLimit().accept(this);
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlUseIndexHint x) {
|
||||
print0(ucase ? "USE INDEX " : "use index ");
|
||||
|
||||
@@ -18,6 +18,10 @@ package com.alibaba.druid.sql.visitor;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2OutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor;
|
||||
@@ -78,7 +82,15 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (stmt.hasBeforeComment()) {
|
||||
stmt.getBeforeCommentsDirect().clear();
|
||||
}
|
||||
stmt.accept(visitor);
|
||||
|
||||
Class<?> stmtClass = stmt.getClass();
|
||||
if (stmtClass == SQLSelectStatement.class) { // only for performance
|
||||
SQLSelectStatement selectStatement = (SQLSelectStatement) stmt;
|
||||
visitor.visit(selectStatement);
|
||||
visitor.postVisit(selectStatement);
|
||||
} else {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
if (visitor.getReplaceCount() == 0
|
||||
|
||||
@@ -1870,6 +1870,8 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
print0(((SQLIdentifierExpr) expr).getName());
|
||||
} else if (expr instanceof SQLPropertyExpr) {
|
||||
visit((SQLPropertyExpr) expr);
|
||||
} else {
|
||||
printExpr(expr);
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ public abstract class WallProvider {
|
||||
|
||||
String mergedSql;
|
||||
try {
|
||||
mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType);
|
||||
mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType, (List<Object>) null);
|
||||
} catch (Exception ex) {
|
||||
// skip
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user