in empire-db/src/main/java/org/apache/empire/db/expr/compare/DBCompareAndOrExpr.java [136:172]
public void addSQL(DBSQLBuilder sql, long context)
{
// Name or Value Only ?
if ((context & CTX_NAME )==0 ||
(context & CTX_VALUE)==0)
{ // add both values separated by ","
left.addSQL(sql, context);
sql.append(",");
right.addSQL(sql, context);
return;
}
// Parenthesis
boolean parenthesis = ((context & CTX_NOPARENTHESIS) == 0) && or;
boolean nested = ((left instanceof DBCompareAndOrExpr) && ((DBCompareAndOrExpr)left).or==false);
if (parenthesis)
sql.append("(");
if (parenthesis && nested)
sql.append("(");
// the left expression
left.addSQL(sql, context);
// Parenthesis
if (parenthesis && nested)
sql.append(")");
// Combine operator
sql.append((or ? " OR " : " AND "));
// Parenthesis
nested = ((right instanceof DBCompareAndOrExpr) && ((DBCompareAndOrExpr)right).or==false);
if (parenthesis && nested)
sql.append("(");
// the right expression
right.addSQL(sql, context);
if (parenthesis && nested)
sql.append(")");
// Parenthesis
if (parenthesis)
sql.append(")");
}