use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr in project druid by alibaba.
the class OracleSelectTest36 method test_0.
public void test_0() throws Exception {
//
String sql = //
"select ID,name from druid_test where (name>=? or name is null) and card_id<?";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
String result = SQLUtils.toOracleString(stmt);
String result_lcase = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("SELECT ID, name" + "\nFROM druid_test" + "\nWHERE (name >= ?" + "\n\t\tOR name IS NULL)" + "\n\tAND card_id < ?", result);
Assert.assertEquals("select ID, name" + "\nfrom druid_test" + "\nwhere (name >= ?" + "\n\t\tor name is null)" + "\n\tand card_id < ?", result_lcase);
{
SQLSelect select = ((SQLSelectStatement) stmt).getSelect();
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) select.getQuery();
SQLBinaryOpExpr where = (SQLBinaryOpExpr) queryBlock.getWhere();
Assert.assertEquals(SQLBinaryOperator.BooleanAnd, where.getOperator());
SQLBinaryOpExpr left = (SQLBinaryOpExpr) where.getLeft();
Assert.assertEquals(SQLBinaryOperator.BooleanOr, left.getOperator());
SQLBinaryOpExpr nameGTEQ = (SQLBinaryOpExpr) left.getLeft();
Assert.assertEquals(SQLBinaryOperator.GreaterThanOrEqual, nameGTEQ.getOperator());
SQLBinaryOpExpr nameIS = (SQLBinaryOpExpr) left.getRight();
Assert.assertEquals(SQLBinaryOperator.Is, nameIS.getOperator());
}
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("druid_test")));
Assert.assertEquals(3, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("druid_test", "ID")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("druid_test", "name")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("druid_test", "card_id")));
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr in project druid by alibaba.
the class OdpsExprParser method equalityRest.
public SQLExpr equalityRest(SQLExpr expr) {
if (lexer.token() == Token.EQEQ) {
SQLExpr rightExp;
lexer.nextToken();
try {
rightExp = bitOr();
} catch (EOFParserException e) {
throw new ParserException("EOF, " + expr + "=", e);
}
rightExp = equalityRest(rightExp);
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
return expr;
}
return super.equalityRest(expr);
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr in project druid by alibaba.
the class OracleExprParser method equalityRest.
public SQLExpr equalityRest(SQLExpr expr) {
SQLExpr rightExp;
if (lexer.token() == Token.EQ) {
lexer.nextToken();
if (lexer.token() == Token.GT) {
lexer.nextToken();
rightExp = expr();
String argumentName = ((SQLIdentifierExpr) expr).getName();
return new OracleArgumentExpr(argumentName, rightExp);
}
rightExp = shift();
rightExp = equalityRest(rightExp);
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
} else if (lexer.token() == Token.BANGEQ) {
lexer.nextToken();
rightExp = shift();
rightExp = equalityRest(rightExp);
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotEqual, rightExp, getDbType());
}
return expr;
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr in project druid by alibaba.
the class WallVisitorUtils method createTenantCondition.
@Deprecated
private static SQLBinaryOpExpr createTenantCondition(WallVisitor visitor, String alias, StatementType statementType, String tableName) {
SQLExpr left, right;
if (alias != null) {
left = new SQLPropertyExpr(new SQLIdentifierExpr(alias), visitor.getConfig().getTenantColumn());
} else {
left = new SQLIdentifierExpr(visitor.getConfig().getTenantColumn());
}
right = generateTenantValue(visitor, alias, statementType, tableName);
SQLBinaryOpExpr tenantCondition = new SQLBinaryOpExpr(left, SQLBinaryOperator.Equality, right);
return tenantCondition;
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr 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);
}
Aggregations