public void unparse(SqlWriter writer, SqlNode[] operands, int leftPrec, int rightPrec) {
   assert operands.length >= 2;
   final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.Simple);
   operands[0].unparse(writer, leftPrec, getLeftPrec());
   final boolean needsSpace = true;
   writer.setNeedWhitespace(needsSpace);
   writer.sep("AS");
   writer.setNeedWhitespace(needsSpace);
   operands[1].unparse(writer, getRightPrec(), rightPrec);
   if (operands.length > 2) {
     final SqlWriter.Frame frame1 = writer.startList(SqlWriter.FrameTypeEnum.Simple, "(", ")");
     for (int i = 2; i < operands.length; i++) {
       SqlNode operand = operands[i];
       writer.sep(",", false);
       operand.unparse(writer, 0, 0);
     }
     writer.endList(frame1);
   }
   writer.endList(frame);
 }
  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);
  }
示例#3
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);
 }