use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat_plus by coderczp.
the class JoinParser method parserWhere.
private void parserWhere(SQLExpr aexpr, String Operator) {
if (aexpr == null) {
return;
}
if (aexpr instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr expr = (SQLBinaryOpExpr) aexpr;
SQLExpr exprL = expr.getLeft();
if (!(exprL instanceof SQLBinaryOpExpr)) {
opSQLExpr((SQLBinaryOpExpr) aexpr, Operator);
} else {
// if (expr.getOperator().getName().equals("AND")) {
if (expr.getOperator() == SQLBinaryOperator.BooleanAnd) {
// parserWhere(exprL);
// parserWhere(expr.getRight());
andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
} else if (expr.getOperator() == SQLBinaryOperator.BooleanOr) {
// .getName().equals("OR")) {
andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
} else {
throw new RuntimeException("Can't identify the operation of of where");
}
}
} else if (aexpr instanceof SQLInListExpr) {
SQLInListExpr expr = (SQLInListExpr) aexpr;
SQLExpr exprL = expr.getExpr();
String field = exprL.toString();
tableFilter.addWhere(field, SQLUtils.toMySqlString(expr), Operator);
}
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project druid by alibaba.
the class SQLMergeTest method merge2.
private String merge2() {
String sql = "INSERT INTO T (F1, F2, F3, F4, F5) VALUES (?, ?, ?, ?, ?), (?, ?, ?, ?, ?), (?, ?, ?, ?, ?)";
StringBuilder out = new StringBuilder();
MySqlOutputVisitor visitor = new MySqlOutputVisitor(out) {
public boolean visit(SQLInListExpr x) {
x.getExpr().accept(this);
if (x.isNot()) {
print(" NOT IN (##)");
} else {
print(" IN (##)");
}
return false;
}
@Override
public boolean visit(MySqlInsertStatement x) {
print("INSERT ");
if (x.isLowPriority()) {
print("LOW_PRIORITY ");
}
if (x.isDelayed()) {
print("DELAYED ");
}
if (x.isHighPriority()) {
print("HIGH_PRIORITY ");
}
if (x.isIgnore()) {
print("IGNORE ");
}
print("INTO ");
x.getTableSource().accept(this);
if (x.getColumns().size() > 0) {
print(" (");
for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
if (i != 0) {
print(", ");
}
x.getColumns().get(i).accept(this);
}
print(")");
}
if (x.getValuesList().size() != 0) {
print(" VALUES ");
int size = x.getValuesList().size();
if (size == 0) {
print("()");
} else {
for (int i = 0; i < 1; ++i) {
if (i != 0) {
print(", ");
}
x.getValuesList().get(i).accept(this);
}
}
}
if (x.getQuery() != null) {
print(" ");
x.getQuery().accept(this);
}
if (x.getDuplicateKeyUpdate().size() != 0) {
print(" ON DUPLICATE KEY UPDATE ");
printAndAccept(x.getDuplicateKeyUpdate(), ", ");
}
return false;
}
};
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
for (SQLStatement statement : statementList) {
statement.accept(visitor);
visitor.println();
}
return out.toString();
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project druid by alibaba.
the class SQLMergeTest method merge.
private String merge() {
StringBuilder out = new StringBuilder();
OracleOutputVisitor visitor = new OracleOutputVisitor(out) {
public boolean visit(SQLInListExpr x) {
x.getExpr().accept(this);
if (x.isNot()) {
print(" NOT IN (##)");
} else {
print(" IN (##)");
}
return false;
}
};
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
for (SQLStatement statement : statementList) {
statement.accept(visitor);
visitor.println();
}
return out.toString();
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project druid by alibaba.
the class SQLASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
SQLASTVisitorAdapter adapter = new SQLASTVisitorAdapter();
new SQLBinaryOpExpr().accept(adapter);
new SQLInListExpr().accept(adapter);
new SQLSelectQueryBlock().accept(adapter);
new SQLDropTableStatement().accept(adapter);
new SQLCreateTableStatement().accept(adapter);
new SQLDeleteStatement().accept(adapter);
new SQLCurrentOfCursorExpr().accept(adapter);
new SQLInsertStatement().accept(adapter);
new SQLUpdateStatement().accept(adapter);
new SQLNotNullConstraint().accept(adapter);
new SQLMethodInvokeExpr().accept(adapter);
new SQLCallStatement().accept(adapter);
new SQLSomeExpr().accept(adapter);
new SQLAnyExpr().accept(adapter);
new SQLAllExpr().accept(adapter);
new SQLDefaultExpr().accept(adapter);
new SQLCommentStatement().accept(adapter);
new SQLDropViewStatement().accept(adapter);
new SQLSavePointStatement().accept(adapter);
new SQLReleaseSavePointStatement().accept(adapter);
new SQLCreateDatabaseStatement().accept(adapter);
new SQLAlterTableDropIndex().accept(adapter);
new SQLOver().accept(adapter);
new SQLWithSubqueryClause().accept(adapter);
new SQLAlterTableAlterColumn().accept(adapter);
new SQLAlterTableStatement().accept(adapter);
new SQLAlterTableDisableConstraint().accept(adapter);
new SQLAlterTableEnableConstraint().accept(adapter);
new SQLColumnCheck().accept(adapter);
new SQLExprHint().accept(adapter);
new SQLAlterTableDropConstraint().accept(adapter);
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project druid by alibaba.
the class EqualTest_inList method test_exits.
public void test_exits() throws Exception {
String sql = "x in (1, 2, 3)";
String sql_c = "x not in (1, 2, 3)";
SQLInListExpr exprA, exprB, exprC;
{
OracleExprParser parser = new OracleExprParser(sql);
exprA = (SQLInListExpr) parser.expr();
}
{
OracleExprParser parser = new OracleExprParser(sql);
exprB = (SQLInListExpr) parser.expr();
}
{
OracleExprParser parser = new OracleExprParser(sql_c);
exprC = (SQLInListExpr) parser.expr();
}
Assert.assertEquals(exprA, exprB);
Assert.assertNotEquals(exprA, exprC);
Assert.assertTrue(exprA.equals(exprA));
Assert.assertFalse(exprA.equals(new Object()));
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
Assert.assertEquals(new SQLInListExpr(), new SQLInListExpr());
Assert.assertEquals(new SQLInListExpr().hashCode(), new SQLInListExpr().hashCode());
}
Aggregations