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