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:
@@ -1041,13 +1041,8 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
final String name = x.getName();
|
||||
if (!this.parameterized) {
|
||||
print0(x.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
return printName(x, name);
|
||||
print0(x.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean printName(SQLName x, String name) {
|
||||
@@ -1535,7 +1530,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (mapTableName != null) {
|
||||
print0(mapTableName);
|
||||
} else {
|
||||
printExpr(owner);
|
||||
if (owner instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr ownerIdent = (SQLIdentifierExpr) owner;
|
||||
printName(ownerIdent, ownerIdent.getName());
|
||||
} else {
|
||||
printExpr(owner);
|
||||
}
|
||||
}
|
||||
print('.');
|
||||
|
||||
@@ -1961,9 +1961,54 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
visit((SQLIdentifierExpr) expr);
|
||||
SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) expr;
|
||||
final String name = identifierExpr.getName();
|
||||
if (!this.parameterized) {
|
||||
print0(name);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean shardingSupport = this.shardingSupport
|
||||
&& this.parameterized;
|
||||
|
||||
if (shardingSupport) {
|
||||
String nameUnwrappe = unwrapShardingTable(name);
|
||||
|
||||
if (!name.equals(nameUnwrappe)) {
|
||||
incrementReplaceCunt();
|
||||
}
|
||||
|
||||
print0(nameUnwrappe);
|
||||
} else {
|
||||
print0(name);
|
||||
}
|
||||
} else if (expr instanceof SQLPropertyExpr) {
|
||||
visit((SQLPropertyExpr) expr);
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
|
||||
SQLExpr owner = propertyExpr.getOwner();
|
||||
|
||||
printTableSourceExpr(owner);
|
||||
print('.');
|
||||
|
||||
final String name = propertyExpr.getName();
|
||||
if (!this.parameterized) {
|
||||
print0(propertyExpr.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
boolean shardingSupport = this.shardingSupport
|
||||
&& this.parameterized;
|
||||
|
||||
if (shardingSupport) {
|
||||
String nameUnwrappe = unwrapShardingTable(name);
|
||||
|
||||
if (!name.equals(nameUnwrappe)) {
|
||||
incrementReplaceCunt();
|
||||
}
|
||||
|
||||
print0(nameUnwrappe);
|
||||
} else {
|
||||
print0(name);
|
||||
}
|
||||
} else {
|
||||
expr.accept(this);
|
||||
}
|
||||
|
||||
@@ -738,5 +738,8 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLBinaryOpExprGroup x);
|
||||
|
||||
void endVisit(SQLBinaryOpExprGroup x);
|
||||
//
|
||||
|
||||
boolean visit(SQLScriptCommitStatement astNode);
|
||||
|
||||
void endVisit(SQLScriptCommitStatement astNode);
|
||||
}
|
||||
|
||||
@@ -1689,6 +1689,16 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
features = VisitorFeature.config(features, feature, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLScriptCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLScriptCommitStatement astNode) {
|
||||
|
||||
}
|
||||
|
||||
public final boolean isEnabled(VisitorFeature feature) {
|
||||
return VisitorFeature.isEnabled(this.features, feature);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user