@Override public void writeWith(SqlCall call, int leftPrec, int rightPrec) { final SqlWith with = (SqlWith) call; final SqlWriter.Frame frame = this.startList(SqlWriter.FrameTypeEnum.WITH, "WITH", ""); for (SqlNode node : with.withList) { this.sep(","); node.unparse(this, 0, 0); } with.body.unparse(this, 100, 100); this.endList(frame); }
private void doWriteLimitOffset(SqlNode fetch, SqlNode offset) { // Dialect does not support OFFSET/FETCH clause. // Assume it uses LIMIT/OFFSET. if (fetch != null) { this.newlineAndIndent(); final Frame fetchFrame = this.startList(FrameTypeEnum.FETCH); this.keyword("LIMIT"); fetch.unparse(this, -1, -1); this.endList(fetchFrame); } if (offset != null) { this.newlineAndIndent(); final Frame offsetFrame = this.startList(FrameTypeEnum.OFFSET); this.keyword("OFFSET"); offset.unparse(this, -1, -1); this.endList(offsetFrame); } }
@Override public void writeWithItem(SqlCall call, SqlWithItem.SqlWithItemOperator sqlWithItemOperator, int leftPrec, int rightPrec) { final SqlWithItem withItem = (SqlWithItem) call; leftPrec = sqlWithItemOperator.getLeftPrec(); rightPrec = sqlWithItemOperator.getRightPrec(); withItem.name.unparse(this, leftPrec, rightPrec); if (withItem.columnList != null) { withItem.columnList.unparse(this, leftPrec, rightPrec); } this.keyword("AS"); Frame frame = this.startList(FrameTypeEnum.WITH_ITEM, "(", ")"); withItem.query.unparse(this, 10, 10); this.endList(frame); } }
@Override public void userDefinedType(SqlDataTypeSpec typeSpec, int leftPrec, int rightPrec) { keyword(typeSpec.getTypeName().getSimple()); // also print precision and scale for user-defined-type int precision = typeSpec.getPrecision(); int scale = typeSpec.getScale(); if (precision >= 0) { final SqlWriter.Frame frame = startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); this.print(precision); if (scale >= 0) { this.sep(",", true); this.print(scale); } this.endList(frame); } }
private void doWriteFetchNext(SqlNode fetch, SqlNode offset) { if (offset == null && !configurer.allowNoOffset()) offset = SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO); if (fetch != null && !configurer.allowNoOrderByWithFetch() && lastFrame != null && lastFrame.getFrameType() != FrameTypeEnum.ORDER_BY_LIST) { // MSSQL requires ORDER_BY list for FETCH clause, so must append one here. DUMMY_ORDER_BY_NODE.unparse(this, 0, 0); } if (offset != null) { this.newlineAndIndent(); final Frame offsetFrame = this.startList(FrameTypeEnum.OFFSET); this.keyword("OFFSET"); offset.unparse(this, -1, -1); this.keyword("ROWS"); this.endList(offsetFrame); } if (fetch != null) { if (!configurer.allowFetchNoRows() && fetch instanceof SqlNumericLiteral) if (((SqlNumericLiteral) fetch).toValue().equals("0")) fetch = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); this.newlineAndIndent(); final Frame fetchFrame = this.startList(FrameTypeEnum.FETCH); this.keyword("FETCH"); this.keyword("NEXT"); fetch.unparse(this, -1, -1); this.keyword("ROWS"); this.keyword("ONLY"); this.endList(fetchFrame); } }
@Override public void writeWith(SqlCall call, int leftPrec, int rightPrec) { final SqlWith with = (SqlWith) call; final SqlWriter.Frame frame = this.startList(SqlWriter.FrameTypeEnum.WITH, "WITH", ""); for (SqlNode node : with.withList) { this.sep(","); node.unparse(this, 0, 0); } with.body.unparse(this, 100, 100); this.endList(frame); }
private void doWriteLimitOffset(SqlNode fetch, SqlNode offset) { // Dialect does not support OFFSET/FETCH clause. // Assume it uses LIMIT/OFFSET. if (fetch != null) { this.newlineAndIndent(); final Frame fetchFrame = this.startList(FrameTypeEnum.FETCH); this.keyword("LIMIT"); fetch.unparse(this, -1, -1); this.endList(fetchFrame); } if (offset != null) { this.newlineAndIndent(); final Frame offsetFrame = this.startList(FrameTypeEnum.OFFSET); this.keyword("OFFSET"); offset.unparse(this, -1, -1); this.endList(offsetFrame); } }
@Override public void writeWithItem(SqlCall call, SqlWithItem.SqlWithItemOperator sqlWithItemOperator, int leftPrec, int rightPrec) { final SqlWithItem withItem = (SqlWithItem) call; leftPrec = sqlWithItemOperator.getLeftPrec(); rightPrec = sqlWithItemOperator.getRightPrec(); withItem.name.unparse(this, leftPrec, rightPrec); if (withItem.columnList != null) { withItem.columnList.unparse(this, leftPrec, rightPrec); } this.keyword("AS"); Frame frame = this.startList(FrameTypeEnum.WITH_ITEM, "(", ")"); withItem.query.unparse(this, 10, 10); this.endList(frame); } }
@Override public void userDefinedType(SqlDataTypeSpec typeSpec, int leftPrec, int rightPrec) { keyword(typeSpec.getTypeName().getSimple()); // also print precision and scale for user-defined-type int precision = typeSpec.getPrecision(); int scale = typeSpec.getScale(); if (precision >= 0) { final SqlWriter.Frame frame = startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); this.print(precision); if (scale >= 0) { this.sep(",", true); this.print(scale); } this.endList(frame); } }
private void doWriteFetchNext(SqlNode fetch, SqlNode offset) { if (offset == null && !configurer.allowNoOffset()) offset = SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO); if (fetch != null && !configurer.allowNoOrderByWithFetch() && lastFrame != null && lastFrame.getFrameType() != FrameTypeEnum.ORDER_BY_LIST) { // MSSQL requires ORDER_BY list for FETCH clause, so must append one here. DUMMY_ORDER_BY_NODE.unparse(this, 0, 0); } if (offset != null) { this.newlineAndIndent(); final Frame offsetFrame = this.startList(FrameTypeEnum.OFFSET); this.keyword("OFFSET"); offset.unparse(this, -1, -1); this.keyword("ROWS"); this.endList(offsetFrame); } if (fetch != null) { if (!configurer.allowFetchNoRows() && fetch instanceof SqlNumericLiteral) if (((SqlNumericLiteral) fetch).toValue().equals("0")) fetch = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); this.newlineAndIndent(); final Frame fetchFrame = this.startList(FrameTypeEnum.FETCH); this.keyword("FETCH"); this.keyword("NEXT"); fetch.unparse(this, -1, -1); this.keyword("ROWS"); this.keyword("ONLY"); this.endList(fetchFrame); } }