public void unparse(SqlWriter writer, SqlNode[] operands, int leftPrec, int rightPrec) {
    final SqlWriter.Frame frame = writer.startList(BetweenFrameType, "", "");
    operands[VALUE_OPERAND].unparse(writer, getLeftPrec(), 0);
    writer.sep(getName());
    operands[SYMFLAG_OPERAND].unparse(writer, 0, 0);

    // If the expression for the lower bound contains a call to an AND
    // operator, we need to wrap the expression in parentheses to prevent
    // the AND from associating with BETWEEN. For example, we should
    // unparse
    //    a BETWEEN b OR (c AND d) OR e AND f
    // as
    //    a BETWEEN (b OR c AND d) OR e) AND f
    // If it were unparsed as
    //    a BETWEEN b OR c AND d OR e AND f
    // then it would be interpreted as
    //    (a BETWEEN (b OR c) AND d) OR (e AND f)
    // which would be wrong.
    int lowerPrec = new AndFinder().containsAnd(operands[LOWER_OPERAND]) ? 100 : 0;
    operands[LOWER_OPERAND].unparse(writer, lowerPrec, lowerPrec);
    writer.sep("AND");
    operands[UPPER_OPERAND].unparse(writer, 0, getRightPrec());
    writer.endList(frame);
  }
Ejemplo n.º 2
0
 public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
   final SqlWriter.Frame frame =
       ((leftPrec > 0) || (rightPrec > 0)) ? writer.startList("(", ")") : writer.startList("", "");
   commaList(writer);
   writer.endList(frame);
 }