提交 950f82d5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Replace more suspicious invocations of Column.getName() with getSQL()

上级 b056815f
...@@ -388,8 +388,8 @@ public class Insert extends CommandWithValues implements ResultTarget { ...@@ -388,8 +388,8 @@ public class Insert extends CommandWithValues implements ResultTarget {
Expression[] row = (currentRow == null) ? valuesExpressionList.get((int) getCurrentRowNumber() - 1) Expression[] row = (currentRow == null) ? valuesExpressionList.get((int) getCurrentRowNumber() - 1)
: new Expression[columns.length]; : new Expression[columns.length];
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
String key = table.getSchema().getName() + "." + StringBuilder builder = table.getSQL(new StringBuilder()).append('.');
table.getName() + "." + columns[i].getName(); String key = columns[i].getSQL(builder).toString();
variableNames.add(key); variableNames.add(key);
Value value; Value value;
if (currentRow != null) { if (currentRow != null) {
......
...@@ -388,58 +388,55 @@ public class ScriptCommand extends ScriptBase { ...@@ -388,58 +388,55 @@ public class ScriptCommand extends ScriptBase {
Index index = plan.getIndex(); Index index = plan.getIndex();
Cursor cursor = index.find(session, null, null); Cursor cursor = index.find(session, null, null);
Column[] columns = table.getColumns(); Column[] columns = table.getColumns();
StatementBuilder buff = new StatementBuilder("INSERT INTO "); StringBuilder builder = new StringBuilder("INSERT INTO ");
table.getSQL(buff.builder()).append('('); table.getSQL(builder).append('(');
for (Column col : columns) { Column.writeColumns(builder, columns);
buff.appendExceptFirst(", "); builder.append(") VALUES");
Parser.quoteIdentifier(buff.builder(), col.getName());
}
buff.append(") VALUES");
if (!simple) { if (!simple) {
buff.append('\n'); builder.append('\n');
} }
buff.append('('); builder.append('(');
String ins = buff.toString(); String ins = builder.toString();
buff = null; builder = null;
while (cursor.next()) { while (cursor.next()) {
Row row = cursor.get(); Row row = cursor.get();
if (buff == null) { if (builder == null) {
buff = new StatementBuilder(ins); builder = new StringBuilder(ins);
} else { } else {
buff.append(",\n("); builder.append(",\n(");
} }
for (int j = 0; j < row.getColumnCount(); j++) { for (int j = 0; j < row.getColumnCount(); j++) {
if (j > 0) { if (j > 0) {
buff.append(", "); builder.append(", ");
} }
Value v = row.getValue(j); Value v = row.getValue(j);
if (v.getType().getPrecision() > lobBlockSize) { if (v.getType().getPrecision() > lobBlockSize) {
int id; int id;
if (v.getValueType() == Value.CLOB) { if (v.getValueType() == Value.CLOB) {
id = writeLobStream(v); id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_CLOB(").append(id).append(')'); builder.append("SYSTEM_COMBINE_CLOB(").append(id).append(')');
} else if (v.getValueType() == Value.BLOB) { } else if (v.getValueType() == Value.BLOB) {
id = writeLobStream(v); id = writeLobStream(v);
buff.append("SYSTEM_COMBINE_BLOB(").append(id).append(')'); builder.append("SYSTEM_COMBINE_BLOB(").append(id).append(')');
} else { } else {
v.getSQL(buff.builder()); v.getSQL(builder);
} }
} else { } else {
v.getSQL(buff.builder()); v.getSQL(builder);
} }
} }
buff.append(')'); builder.append(')');
count++; count++;
if ((count & 127) == 0) { if ((count & 127) == 0) {
checkCanceled(); checkCanceled();
} }
if (simple || buff.length() > Constants.IO_BUFFER_SIZE) { if (simple || builder.length() > Constants.IO_BUFFER_SIZE) {
add(buff.toString(), true); add(builder.toString(), true);
buff = null; builder = null;
} }
} }
if (buff != null) { if (builder != null) {
add(buff.toString(), true); add(builder.toString(), true);
} }
return count; return count;
} }
......
...@@ -1478,11 +1478,7 @@ public class Select extends Query { ...@@ -1478,11 +1478,7 @@ public class Select extends Query {
t.getSchema().getSQL(buff.builder()).append('.'); t.getSchema().getSQL(buff.builder()).append('.');
Parser.quoteIdentifier(buff.builder(), t.getName()) Parser.quoteIdentifier(buff.builder(), t.getName())
.append('('); .append('(');
buff.resetCount(); Column.writeColumns(buff.builder(), t.getColumns());
for (Column c : t.getColumns()) {
buff.appendExceptFirst(",");
buff.append(c.getName());
}
buff.append(") AS "); buff.append(") AS ");
t.getSQL(buff.builder()).append('\n'); t.getSQL(buff.builder()).append('\n');
} }
......
...@@ -575,7 +575,7 @@ public class ConstraintReferential extends Constraint { ...@@ -575,7 +575,7 @@ public class ConstraintReferential extends Constraint {
buff.resetCount(); buff.resetCount();
for (IndexColumn c : columns) { for (IndexColumn c : columns) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
Parser.quoteIdentifier(buff.builder(), c.column.getName()).append("=?"); c.column.getSQL(buff.builder()).append("=?");
} }
} }
...@@ -584,7 +584,7 @@ public class ConstraintReferential extends Constraint { ...@@ -584,7 +584,7 @@ public class ConstraintReferential extends Constraint {
buff.resetCount(); buff.resetCount();
for (IndexColumn c : columns) { for (IndexColumn c : columns) {
buff.appendExceptFirst(" AND "); buff.appendExceptFirst(" AND ");
Parser.quoteIdentifier(buff.builder(), c.column.getName()).append("=?"); c.column.getSQL(buff.builder()).append("=?");
} }
} }
......
...@@ -58,7 +58,7 @@ public class ConstraintUnique extends Constraint { ...@@ -58,7 +58,7 @@ public class ConstraintUnique extends Constraint {
buff.append(' ').append(getConstraintType().getSqlName()).append('('); buff.append(' ').append(getConstraintType().getSqlName()).append('(');
for (IndexColumn c : columns) { for (IndexColumn c : columns) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
Parser.quoteIdentifier(buff.builder(), c.column.getName()); c.column.getSQL(buff.builder());
} }
buff.append(')'); buff.append(')');
if (internalIndex && indexOwner && forTable == this.table) { if (internalIndex && indexOwner && forTable == this.table) {
......
...@@ -1713,10 +1713,15 @@ public class Function extends Expression implements FunctionCall { ...@@ -1713,10 +1713,15 @@ public class Function extends Expression implements FunctionCall {
} }
break; break;
} }
case VALUES: case VALUES: {
result = session.getVariable(args[0].getSchemaName() + "." + Expression a0 = args[0];
args[0].getTableName() + "." + args[0].getColumnName()); StringBuilder builder = new StringBuilder();
Parser.quoteIdentifier(builder, a0.getSchemaName()).append('.');
Parser.quoteIdentifier(builder, a0.getTableName()).append('.');
Parser.quoteIdentifier(builder, a0.getColumnName());
result = session.getVariable(builder.toString());
break; break;
}
case SIGNAL: { case SIGNAL: {
String sqlState = v0.getString(); String sqlState = v0.getString();
if (sqlState.startsWith("00") || !SIGNAL_PATTERN.matcher(sqlState).matches()) { if (sqlState.startsWith("00") || !SIGNAL_PATTERN.matcher(sqlState).matches()) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论