提交 aa4c335b authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add more getSQL(StringBuilder) methods

上级 f592e317
...@@ -303,7 +303,7 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -303,7 +303,7 @@ public class Insert extends Prepared implements ResultTarget {
if (e == null) { if (e == null) {
buff.append("DEFAULT"); buff.append("DEFAULT");
} else { } else {
buff.append(e.getSQL()); e.getSQL(buff.builder());
} }
} }
buff.append(')'); buff.append(')');
......
...@@ -58,8 +58,8 @@ public class ConstraintCheck extends Constraint { ...@@ -58,8 +58,8 @@ public class ConstraintCheck extends Constraint {
if (comment != null) { if (comment != null) {
buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment)); buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
} }
buff.append(" CHECK").append(StringUtils.enclose(expr.getSQL())) buff.append(" CHECK(");
.append(" NOCHECK"); expr.getUnenclosedSQL(buff).append(") NOCHECK");
return buff.toString(); return buff.toString();
} }
......
...@@ -13,7 +13,6 @@ import org.h2.engine.Session; ...@@ -13,7 +13,6 @@ import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.util.StatementBuilder;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -46,16 +45,16 @@ public class TableFunction extends Function { ...@@ -46,16 +45,16 @@ public class TableFunction extends Function {
} }
@Override @Override
public String getSQL() { public StringBuilder getSQL(StringBuilder builder) {
StatementBuilder buff = new StatementBuilder(getName()); builder.append(getName()).append('(');
buff.append('('); for (int i = 0; i < args.length; i++) {
int i = 0; if (i > 0) {
for (Expression e : args) { builder.append(", ");
buff.appendExceptFirst(", "); }
buff.append(columnList[i++].getCreateSQL()).append('='); builder.append(columnList[i].getCreateSQL()).append('=');
e.getSQL(buff.builder()); args[i].getSQL(builder);
} }
return buff.append(')').toString(); return builder.append(')');
} }
......
...@@ -827,7 +827,8 @@ public class Aggregate extends AbstractAggregate { ...@@ -827,7 +827,8 @@ public class Aggregate extends AbstractAggregate {
builder.append("(DISTINCT "); builder.append("(DISTINCT ");
on.getSQL(builder).append(')'); on.getSQL(builder).append(')');
} else { } else {
builder.append(StringUtils.enclose(on.getSQL())); builder.append('(');
on.getUnenclosedSQL(builder).append(')');
} }
return appendTailConditions(builder); return appendTailConditions(builder);
} }
......
...@@ -351,7 +351,8 @@ public abstract class DataAnalysisOperation extends Expression { ...@@ -351,7 +351,8 @@ public abstract class DataAnalysisOperation extends Expression {
protected StringBuilder appendTailConditions(StringBuilder builder) { protected StringBuilder appendTailConditions(StringBuilder builder) {
if (over != null) { if (over != null) {
builder.append(' ').append(over.getSQL()); builder.append(' ');
over.getSQL(builder);
} }
return builder; return builder;
} }
......
...@@ -203,16 +203,15 @@ public final class Window { ...@@ -203,16 +203,15 @@ public final class Window {
} }
/** /**
* Returns SQL representation. * Appends SQL representation to the specified builder.
* *
* @return SQL representation. * @param builder
* @see Expression#getSQL() * string builder
* @return the specified string builder
* @see Expression#getSQL(StringBuilder)
*/ */
public String getSQL() { public StringBuilder getSQL(StringBuilder builder) {
if (partitionBy == null && orderBy == null && frame == null) { builder.append("OVER (");
return "OVER ()";
}
StringBuilder builder = new StringBuilder().append("OVER (");
if (partitionBy != null) { if (partitionBy != null) {
builder.append("PARTITION BY "); builder.append("PARTITION BY ");
for (int i = 0; i < partitionBy.size(); i++) { for (int i = 0; i < partitionBy.size(); i++) {
...@@ -227,9 +226,9 @@ public final class Window { ...@@ -227,9 +226,9 @@ public final class Window {
if (builder.charAt(builder.length() - 1) != '(') { if (builder.charAt(builder.length() - 1) != '(') {
builder.append(' '); builder.append(' ');
} }
builder.append(frame.getSQL()); frame.getSQL(builder);
} }
return builder.append(')').toString(); return builder.append(')');
} }
/** /**
...@@ -256,7 +255,7 @@ public final class Window { ...@@ -256,7 +255,7 @@ public final class Window {
@Override @Override
public String toString() { public String toString() {
return getSQL(); return getSQL(new StringBuilder()).toString();
} }
} }
...@@ -584,23 +584,27 @@ public final class WindowFrame { ...@@ -584,23 +584,27 @@ public final class WindowFrame {
} }
/** /**
* Returns SQL representation. * Append SQL representation to the specified builder.
* *
* @return SQL representation. * @param builder
* @see org.h2.expression.Expression#getSQL() * string builder
* @return the specified string builder
* @see org.h2.expression.Expression#getSQL(StringBuilder)
*/ */
public String getSQL() { public StringBuilder getSQL(StringBuilder builder) {
StringBuilder builder = new StringBuilder();
builder.append(units.getSQL()); builder.append(units.getSQL());
if (following == null) { if (following == null) {
builder.append(' ').append(starting.getSQL(false)); builder.append(' ');
starting.getSQL(builder, false);
} else { } else {
builder.append(" BETWEEN ").append(starting.getSQL(false)).append(" AND ").append(following.getSQL(true)); builder.append(" BETWEEN ");
starting.getSQL(builder, false).append(" AND ");
following.getSQL(builder, true);
} }
if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) { if (exclusion != WindowFrameExclusion.EXCLUDE_NO_OTHERS) {
builder.append(' ').append(exclusion.getSQL()); builder.append(' ').append(exclusion.getSQL());
} }
return builder.toString(); return builder;
} }
} }
...@@ -52,20 +52,21 @@ public class WindowFrameBound { ...@@ -52,20 +52,21 @@ public class WindowFrameBound {
} }
/** /**
* Returns SQL representation. * Appends SQL representation to the specified builder.
* *
* @param builder
* string builder
* @param following * @param following
* if false return SQL for starting clause, if true return SQL * if false return SQL for starting clause, if true return SQL
* for following clause * for following clause
* @return SQL representation. * @return the specified string builder
* @see Expression#getSQL() * @see Expression#getSQL(StringBuilder)
*/ */
public String getSQL(boolean following) { public StringBuilder getSQL(StringBuilder builder, boolean following) {
if (type == WindowFrameBoundType.PRECEDING || type == WindowFrameBoundType.FOLLOWING) { if (type == WindowFrameBoundType.PRECEDING || type == WindowFrameBoundType.FOLLOWING) {
StringBuilder builder = new StringBuilder(); value.getSQL(builder).append(' ');
return value.getSQL(builder).append(' ').append(type.getSQL()).toString();
} }
return type.getSQL(); return builder.append(type.getSQL());
} }
} }
...@@ -546,20 +546,17 @@ public class Column { ...@@ -546,20 +546,17 @@ public class Column {
} }
if (defaultExpression != null) { if (defaultExpression != null) {
String sql = defaultExpression.getSQL(); if (isComputed) {
if (sql != null) { buff.append(" AS ");
if (isComputed) { defaultExpression.getSQL(buff);
buff.append(" AS ").append(sql); } else if (defaultExpression != null) {
} else if (defaultExpression != null) { buff.append(" DEFAULT ");
buff.append(" DEFAULT ").append(sql); defaultExpression.getSQL(buff);
}
} }
} }
if (onUpdateExpression != null) { if (onUpdateExpression != null) {
String sql = onUpdateExpression.getSQL(); buff.append(" ON UPDATE ");
if (sql != null) { onUpdateExpression.getSQL(buff);
buff.append(" ON UPDATE ").append(sql);
}
} }
if (!nullable) { if (!nullable) {
buff.append(" NOT NULL"); buff.append(" NOT NULL");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论