use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleSchemaStatVisitor method visit.
@Override
public boolean visit(OracleSelectJoin x) {
super.visit(x);
for (SQLExpr item : x.getUsing()) {
if (item instanceof SQLIdentifierExpr) {
String columnName = ((SQLIdentifierExpr) item).getName();
String leftTable = (String) x.getLeft().getAttribute(ATTR_TABLE);
String rightTable = (String) x.getRight().getAttribute(ATTR_TABLE);
if (leftTable != null && rightTable != null) {
Relationship relationship = new Relationship();
relationship.setLeft(new Column(leftTable, columnName));
relationship.setRight(new Column(rightTable, columnName));
relationship.setOperator("USING");
relationships.add(relationship);
}
if (leftTable != null) {
addColumn(leftTable, columnName);
}
if (rightTable != null) {
addColumn(rightTable, columnName);
}
}
}
return false;
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleSchemaStatVisitor method visit.
public boolean visit(OracleSelectTableReference x) {
SQLExpr expr = x.getExpr();
if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvoke = (SQLMethodInvokeExpr) expr;
if ("TABLE".equalsIgnoreCase(methodInvoke.getMethodName()) && methodInvoke.getParameters().size() == 1) {
expr = methodInvoke.getParameters().get(0);
}
}
Map<String, String> aliasMap = getAliasMap();
if (expr instanceof SQLName) {
String ident;
if (expr instanceof SQLPropertyExpr) {
String owner = ((SQLPropertyExpr) expr).getOwner().toString();
String name = ((SQLPropertyExpr) expr).getName();
if (aliasMap.containsKey(owner)) {
owner = aliasMap.get(owner);
}
ident = owner + "." + name;
} else {
ident = expr.toString();
}
if (containsSubQuery(ident)) {
return false;
}
if ("DUAL".equalsIgnoreCase(ident)) {
return false;
}
x.putAttribute(ATTR_TABLE, ident);
TableStat stat = getTableStat(ident);
Mode mode = getMode();
switch(mode) {
case Delete:
stat.incrementDeleteCount();
break;
case Insert:
stat.incrementInsertCount();
break;
case Update:
stat.incrementUpdateCount();
break;
case Select:
stat.incrementSelectCount();
break;
case Merge:
stat.incrementMergeCount();
break;
default:
break;
}
putAliasMap(aliasMap, x.getAlias(), ident);
putAliasMap(aliasMap, ident, ident);
return false;
}
accept(x.getExpr());
return false;
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class OracleUpdateParser method parseReturn.
private void parseReturn(OracleUpdateStatement update) {
if (identifierEquals("RETURN") || lexer.token() == Token.RETURNING) {
lexer.nextToken();
for (; ; ) {
SQLExpr item = this.exprParser.expr();
update.getReturning().add(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.INTO);
for (; ; ) {
SQLExpr item = this.exprParser.expr();
update.getReturningInto().add(item);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
}
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class SQLServerStatementParser method parseExecParameter.
/**
* SQLServer parse Parameter statement support out type
* @author zz [455910092@qq.com]
*/
public void parseExecParameter(Collection<SQLServerParameter> exprCol, SQLObject parent) {
if (lexer.token() == Token.RPAREN || lexer.token() == Token.RBRACKET) {
return;
}
if (lexer.token() == Token.EOF) {
return;
}
SQLServerParameter param = new SQLServerParameter();
SQLExpr expr = this.exprParser.expr();
expr.setParent(parent);
param.setExpr(expr);
if (lexer.token() == Token.OUT) {
param.setType(true);
accept(Token.OUT);
}
exprCol.add(param);
while (lexer.token() == Token.COMMA) {
lexer.nextToken();
param = new SQLServerParameter();
expr = this.exprParser.expr();
expr.setParent(parent);
param.setExpr(expr);
if (lexer.token() == Token.OUT) {
param.setType(true);
accept(Token.OUT);
}
exprCol.add(param);
}
}
use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.
the class ParameterizedOutputVisitorUtils method merge.
public static SQLBinaryOpExpr merge(ParameterizedVisitor v, SQLBinaryOpExpr x) {
SQLExpr left = x.getLeft();
SQLExpr right = x.getRight();
SQLObject parent = x.getParent();
if (left instanceof SQLLiteralExpr && right instanceof SQLLiteralExpr) {
if (//
x.getOperator() == SQLBinaryOperator.Equality || x.getOperator() == SQLBinaryOperator.NotEqual) {
if ((left instanceof SQLIntegerExpr) && (right instanceof SQLIntegerExpr)) {
if (((SQLIntegerExpr) left).getNumber().intValue() < 100) {
left.putAttribute(ATTR_PARAMS_SKIP, true);
}
if (((SQLIntegerExpr) right).getNumber().intValue() < 100) {
right.putAttribute(ATTR_PARAMS_SKIP, true);
}
} else {
left.putAttribute(ATTR_PARAMS_SKIP, true);
right.putAttribute(ATTR_PARAMS_SKIP, true);
}
}
return x;
}
for (; ; ) {
if (x.getRight() instanceof SQLBinaryOpExpr) {
if (x.getLeft() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr leftBinaryExpr = (SQLBinaryOpExpr) x.getLeft();
if (leftBinaryExpr.getRight().equals(x.getRight())) {
x = leftBinaryExpr;
v.incrementReplaceCunt();
continue;
}
}
SQLExpr mergedRight = merge(v, (SQLBinaryOpExpr) x.getRight());
if (mergedRight != x.getRight()) {
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), mergedRight);
v.incrementReplaceCunt();
}
x.setParent(parent);
}
break;
}
if (x.getLeft() instanceof SQLBinaryOpExpr) {
SQLExpr mergedLeft = merge(v, (SQLBinaryOpExpr) x.getLeft());
if (mergedLeft != x.getLeft()) {
SQLBinaryOpExpr tmp = new SQLBinaryOpExpr(mergedLeft, x.getOperator(), x.getRight());
tmp.setParent(parent);
x = tmp;
v.incrementReplaceCunt();
}
}
// ID = ? OR ID = ? => ID = ?
if (x.getOperator() == SQLBinaryOperator.BooleanOr) {
if ((x.getLeft() instanceof SQLBinaryOpExpr) && (x.getRight() instanceof SQLBinaryOpExpr)) {
SQLBinaryOpExpr leftBinary = (SQLBinaryOpExpr) x.getLeft();
SQLBinaryOpExpr rightBinary = (SQLBinaryOpExpr) x.getRight();
if (mergeEqual(leftBinary, rightBinary)) {
v.incrementReplaceCunt();
leftBinary.setParent(x.getParent());
putMergedArribute(leftBinary, rightBinary);
return leftBinary;
}
if (//
isLiteralExpr(leftBinary.getLeft()) && leftBinary.getOperator() == SQLBinaryOperator.BooleanOr) {
if (mergeEqual(leftBinary.getRight(), x.getRight())) {
v.incrementReplaceCunt();
putMergedArribute(leftBinary, rightBinary);
return leftBinary;
}
}
}
}
return x;
}
Aggregations