use of net.sf.jsqlparser.expression.operators.conditional.XorExpression in project JSqlParser by JSQLParser.
the class ExpressionVisitorAdapterTest method testXorExpression.
@Test
public void testXorExpression() throws JSQLParserException {
final List<Expression> exprList = new ArrayList<>();
Select select = (Select) CCJSqlParserUtil.parse("SELECT * FROM table WHERE foo XOR bar");
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
Expression where = plainSelect.getWhere();
where.accept(new ExpressionVisitorAdapter() {
@Override
public void visit(XorExpression expr) {
super.visit(expr);
exprList.add(expr.getLeftExpression());
exprList.add(expr.getRightExpression());
}
});
assertEquals(2, exprList.size());
assertTrue(exprList.get(0) instanceof Column);
assertEquals("foo", ((Column) exprList.get(0)).getColumnName());
assertTrue(exprList.get(1) instanceof Column);
assertEquals("bar", ((Column) exprList.get(1)).getColumnName());
}
use of net.sf.jsqlparser.expression.operators.conditional.XorExpression in project JSqlParser by JSQLParser.
the class JSQLParserFluentModelTests method testParseAndBuildForXORComplexCondition.
@Test
public void testParseAndBuildForXORComplexCondition() throws JSQLParserException {
String statement = "SELECT * FROM tab1 AS t1 WHERE " + "a AND b OR c XOR d";
Statement parsed = TestUtils.assertSqlCanBeParsedAndDeparsed(statement);
Table t1 = new Table("tab1").withAlias(new Alias("t1", true));
XorExpression where = new XorExpression().withLeftExpression(new OrExpression().withLeftExpression(new AndExpression().withLeftExpression(new Column("a")).withRightExpression(new Column("b"))).withRightExpression(new Column("c"))).withRightExpression(new Column("d"));
Select select = new Select().withSelectBody(new PlainSelect().addSelectItems(new AllColumns()).withFromItem(t1).withWhere(where));
assertDeparse(select, statement);
assertEqualsObjectTree(select, parsed);
}
use of net.sf.jsqlparser.expression.operators.conditional.XorExpression in project JSqlParser by JSQLParser.
the class JSQLParserFluentModelTests method testParseAndBuildForXORs.
@Test
public void testParseAndBuildForXORs() throws JSQLParserException {
String statement = "SELECT * FROM tab1 AS t1 WHERE " + "a XOR b XOR c";
Statement parsed = TestUtils.assertSqlCanBeParsedAndDeparsed(statement);
Table t1 = new Table("tab1").withAlias(new Alias("t1", true));
XorExpression where = new XorExpression().withLeftExpression(new XorExpression().withLeftExpression(new Column("a")).withRightExpression(new Column("b"))).withRightExpression(new Column("c"));
Select select = new Select().withSelectBody(new PlainSelect().addSelectItems(new AllColumns()).withFromItem(t1).withWhere(where));
assertDeparse(select, statement);
assertEqualsObjectTree(select, parsed);
}
use of net.sf.jsqlparser.expression.operators.conditional.XorExpression in project JSqlParser by JSQLParser.
the class JSQLParserFluentModelTests method testParseAndBuildForXOR.
@Test
public void testParseAndBuildForXOR() throws JSQLParserException {
String statement = "SELECT * FROM tab1 AS t1 JOIN tab2 t2 ON t1.ref = t2.id " + "WHERE (t1.col1 XOR t2.col2) AND t1.col3 IN ('B', 'C') XOR t2.col4";
Statement parsed = TestUtils.assertSqlCanBeParsedAndDeparsed(statement);
Table t1 = new Table("tab1").withAlias(new Alias("t1", true));
Table t2 = new Table("tab2").withAlias(new Alias("t2", false));
XorExpression where = new XorExpression().withLeftExpression(new AndExpression().withLeftExpression(new Parenthesis(new XorExpression().withLeftExpression(new Column(asList("t1", "col1"))).withRightExpression(new Column(asList("t2", "col2"))))).withRightExpression(new InExpression().withLeftExpression(new Column(asList("t1", "col3"))).withRightItemsList(new ExpressionList(new StringValue("B"), new StringValue("C"))))).withRightExpression(new Column(asList("t2", "col4")));
Select select = new Select().withSelectBody(new PlainSelect().addSelectItems(new AllColumns()).withFromItem(t1).addJoins(new Join().withRightItem(t2).withOnExpression(new EqualsTo(new Column(asList("t1", "ref")), new Column(asList("t2", "id"))))).withWhere(where));
ExpressionList list = select.getSelectBody(PlainSelect.class).getWhere(XorExpression.class).getLeftExpression(AndExpression.class).getRightExpression(InExpression.class).getRightItemsList(ExpressionList.class);
List<Expression> elist = list.getExpressions();
list.setExpressions(elist);
assertDeparse(select, statement);
assertEqualsObjectTree(parsed, select);
}
Aggregations