提交 4656131a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add and use Column.getSQL(StringBuilder)

上级 a6c94ddf
......@@ -409,9 +409,13 @@ public class AlterTableAlterColumn extends CommandWithColumns {
if (type == CommandInterface.ALTER_TABLE_ADD_COLUMN &&
columnsToAdd != null && columnsToAdd.contains(nc)) {
Expression def = nc.getDefaultExpression();
columnList.append(def == null ? "NULL" : def.getSQL());
if (def == null) {
columnList.append("NULL");
} else {
columnList.append(nc.getSQL());
def.getSQL(columnList);
}
} else {
nc.getSQL(columnList);
}
}
String newTableName = newTable.getName();
......@@ -589,7 +593,7 @@ public class AlterTableAlterColumn extends CommandWithColumns {
private void checkNoNullValues(Table table) {
StringBuilder builder = new StringBuilder("SELECT COUNT(*) FROM ");
table.getSQL(builder).append(" WHERE ");
builder.append(oldColumn.getSQL()).append(" IS NULL");
oldColumn.getSQL(builder).append(" IS NULL");
String sql = builder.toString();
Prepared command = session.prepare(sql);
ResultInterface result = command.query(0);
......
......@@ -110,7 +110,8 @@ public class Analyze extends DefineCommand {
// the selectivity is not required
buff.append("MAX(NULL)");
} else {
buff.append("SELECTIVITY(").append(col.getSQL()).append(')');
buff.append("SELECTIVITY(");
col.getSQL(buff.builder()).append(')');
}
}
buff.append(" FROM ");
......
......@@ -273,7 +273,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
table.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
c.getSQL(buff.builder());
}
buff.append(")\n");
if (insertFromSelect) {
......@@ -409,7 +409,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
for (Column column : duplicateKeyAssignmentMap.keySet()) {
buff.appendExceptFirst(", ");
Expression ex = duplicateKeyAssignmentMap.get(column);
buff.append(column.getSQL()).append('=');
column.getSQL(buff.builder()).append('=');
ex.getSQL(buff.builder());
}
buff.append(" WHERE ");
......
......@@ -210,7 +210,7 @@ public class Merge extends CommandWithValues {
targetTable.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
c.getSQL(buff.builder());
}
buff.append(')');
if (keys != null) {
......@@ -218,7 +218,7 @@ public class Merge extends CommandWithValues {
buff.resetCount();
for (Column c : keys) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
c.getSQL(buff.builder());
}
buff.append(')');
}
......@@ -279,13 +279,13 @@ public class Merge extends CommandWithValues {
targetTable.getSQL(buff.builder()).append(" SET ");
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL()).append("=?");
c.getSQL(buff.builder()).append("=?");
}
buff.append(" WHERE ");
buff.resetCount();
for (Column c : keys) {
buff.appendExceptFirst(" AND ");
buff.append(c.getSQL()).append("=?");
c.getSQL(buff.builder()).append("=?");
}
String sql = buff.toString();
update = session.prepare(sql);
......
......@@ -199,7 +199,7 @@ public class Replace extends CommandWithValues {
table.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
c.getSQL(buff.builder());
}
buff.append(')');
buff.append('\n');
......@@ -273,13 +273,13 @@ public class Replace extends CommandWithValues {
table.getSQL(buff.builder()).append(" SET ");
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL()).append("=?");
c.getSQL(buff.builder()).append("=?");
}
buff.append(" WHERE ");
buff.resetCount();
for (Column c : keys) {
buff.appendExceptFirst(" AND ");
buff.append(c.getSQL()).append("=?");
c.getSQL(buff.builder()).append("=?");
}
String sql = buff.toString();
update = session.prepare(sql);
......
......@@ -218,7 +218,7 @@ public class Update extends Prepared {
builder.append(",\n ");
}
Column c = columns.get(i);
builder.append(c.getSQL()).append(" = ");
c.getSQL(builder).append(" = ");
expressionMap.get(c).getSQL(builder);
}
if (condition != null) {
......
......@@ -69,7 +69,7 @@ public class ExpressionColumn extends Expression {
if (derivedName != null) {
Parser.quoteIdentifier(builder, derivedName);
} else {
builder.append(column.getSQL());
column.getSQL(builder);
}
} else {
Parser.quoteIdentifier(builder, columnName);
......
......@@ -178,7 +178,7 @@ public class IndexCondition {
return "FALSE";
}
StringBuilder builder = new StringBuilder();
builder.append(column.getSQL());
column.getSQL(builder);
switch (compareType) {
case Comparison.EQUAL:
builder.append(" = ");
......
......@@ -95,7 +95,7 @@ public class LinkedIndex extends BaseIndex {
buff.appendOnlyFirst(" WHERE ");
buff.appendExceptFirst(" AND ");
Column col = table.getColumn(i);
buff.append(col.getSQL());
col.getSQL(buff.builder());
if (v == ValueNull.INSTANCE) {
buff.append(" IS NULL");
} else {
......@@ -111,7 +111,7 @@ public class LinkedIndex extends BaseIndex {
buff.appendOnlyFirst(" WHERE ");
buff.appendExceptFirst(" AND ");
Column col = table.getColumn(i);
buff.append(col.getSQL());
col.getSQL(buff.builder());
if (v == ValueNull.INSTANCE) {
buff.append(" IS NULL");
} else {
......@@ -192,7 +192,7 @@ public class LinkedIndex extends BaseIndex {
for (int i = 0; i < row.getColumnCount(); i++) {
buff.appendExceptFirst("AND ");
Column col = table.getColumn(i);
buff.append(col.getSQL());
col.getSQL(buff.builder());
Value v = row.getValue(i);
if (isNull(v)) {
buff.append(" IS NULL ");
......@@ -227,7 +227,7 @@ public class LinkedIndex extends BaseIndex {
buff.append(targetTableName).append(" SET ");
for (int i = 0; i < newRow.getColumnCount(); i++) {
buff.appendExceptFirst(", ");
buff.append(table.getColumn(i).getSQL()).append('=');
table.getColumn(i).getSQL(buff.builder()).append('=');
Value v = newRow.getValue(i);
if (v == null) {
buff.append("DEFAULT");
......@@ -241,7 +241,7 @@ public class LinkedIndex extends BaseIndex {
for (int i = 0; i < oldRow.getColumnCount(); i++) {
Column col = table.getColumn(i);
buff.appendExceptFirst(" AND ");
buff.append(col.getSQL());
col.getSQL(buff.builder());
Value v = oldRow.getValue(i);
if (isNull(v)) {
buff.append(" IS NULL");
......
......@@ -248,6 +248,10 @@ public class Column {
return Parser.quoteIdentifier(name);
}
public StringBuilder getSQL(StringBuilder builder) {
return Parser.quoteIdentifier(builder, name);
}
public String getName() {
return name;
}
......
......@@ -35,9 +35,10 @@ public class IndexColumn {
* @return the SQL snippet
*/
public String getSQL() {
StringBuilder buff = new StringBuilder(column.getSQL());
SortOrder.typeToString(buff, sortType);
return buff.toString();
StringBuilder builder = new StringBuilder();
column.getSQL(builder);
SortOrder.typeToString(builder, sortType);
return builder.toString();
}
/**
......
......@@ -345,7 +345,7 @@ public class TableView extends Table {
buff.append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
c.getSQL(buff.builder());
}
buff.append(')');
} else if (columnTemplates != null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论