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

Use DbObject.getSQL(StringBuilder) where possible

上级 4f34f37d
......@@ -208,8 +208,9 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
session.getUser().checkRight(refTable, Right.ALL);
if (!refTable.canReference()) {
throw DbException.getUnsupportedException("Reference " +
refTable.getSQL());
StringBuilder builder = new StringBuilder("Reference ");
refTable.getSQL(builder);
throw DbException.getUnsupportedException(builder.toString());
}
boolean isOwner = false;
IndexColumn.mapColumns(indexColumns, table);
......
......@@ -296,7 +296,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
// (because the column to drop is referenced or so)
checkViews(table, newTable);
} catch (DbException e) {
execute("DROP TABLE " + newTable.getSQL(), true);
StringBuilder builder = new StringBuilder("DROP TABLE ");
newTable.getSQL(builder);
execute(builder.toString(), true);
throw e;
}
String tableName = table.getName();
......@@ -304,7 +306,9 @@ public class AlterTableAlterColumn extends CommandWithColumns {
for (TableView view : dependentViews) {
table.removeDependentView(view);
}
execute("DROP TABLE " + table.getSQL() + " IGNORE", true);
StringBuilder builder = new StringBuilder("DROP TABLE ");
table.getSQL(builder).append(" IGNORE");
execute(builder.toString(), true);
db.renameSchemaObject(session, newTable, tableName);
for (DbObject child : newTable.getChildren()) {
if (child instanceof Sequence) {
......@@ -475,7 +479,8 @@ public class AlterTableAlterColumn extends CommandWithColumns {
}
}
StringBuilder buff = new StringBuilder();
buff.append("INSERT INTO ").append(newTable.getSQL());
buff.append("INSERT INTO ");
newTable.getSQL(buff);
buff.append(" SELECT ");
if (columnList.length() == 0) {
// special case: insert into test select * from
......@@ -483,13 +488,16 @@ public class AlterTableAlterColumn extends CommandWithColumns {
} else {
buff.append(columnList);
}
buff.append(" FROM ").append(table.getSQL());
buff.append(" FROM ");
table.getSQL(buff);
try {
execute(buff.toString(), true);
} catch (Throwable t) {
// data was not inserted due to data conversion error or some
// unexpected reason
execute("DROP TABLE " + newTable.getSQL(), true);
StringBuilder builder = new StringBuilder("DROP TABLE ");
newTable.getSQL(builder);
execute(builder.toString(), true);
throw t;
}
for (String sql : children) {
......@@ -579,9 +587,10 @@ public class AlterTableAlterColumn extends CommandWithColumns {
}
private void checkNoNullValues(Table table) {
String sql = "SELECT COUNT(*) FROM " +
table.getSQL() + " WHERE " +
oldColumn.getSQL() + " IS NULL";
StringBuilder builder = new StringBuilder("SELECT COUNT(*) FROM ");
table.getSQL(builder).append(" WHERE ");
builder.append(oldColumn.getSQL()).append(" IS NULL");
String sql = builder.toString();
Prepared command = session.prepare(sql);
ResultInterface result = command.query(0);
result.next();
......
......@@ -113,7 +113,8 @@ public class Analyze extends DefineCommand {
buff.append("SELECTIVITY(").append(col.getSQL()).append(')');
}
}
buff.append(" FROM ").append(table.getSQL());
buff.append(" FROM ");
table.getSQL(buff.builder());
if (sample > 0) {
buff.append(" FETCH FIRST ROW ONLY SAMPLE_SIZE ? ");
}
......
......@@ -64,9 +64,9 @@ public class CreateDomain extends DefineCommand {
}
Table table = session.getDatabase().getFirstUserTable();
if (table != null) {
throw DbException.get(
ErrorCode.DOMAIN_ALREADY_EXISTS_1,
typeName + " (" + table.getSQL() + ")");
StringBuilder builder = new StringBuilder(typeName).append(" (");
table.getSQL(builder).append(')');
throw DbException.get(ErrorCode.DOMAIN_ALREADY_EXISTS_1, builder.toString());
}
}
int id = getObjectId();
......
......@@ -270,7 +270,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
@Override
public String getPlanSQL() {
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
buff.append(table.getSQL()).append('(');
table.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
......@@ -405,7 +405,7 @@ public class Insert extends CommandWithValues implements ResultTarget {
}
StatementBuilder buff = new StatementBuilder("UPDATE ");
buff.append(table.getSQL()).append(" SET ");
table.getSQL(buff.builder()).append(" SET ");
for (Column column : duplicateKeyAssignmentMap.keySet()) {
buff.appendExceptFirst(", ");
Expression ex = duplicateKeyAssignmentMap.get(column);
......
......@@ -207,7 +207,7 @@ public class Merge extends CommandWithValues {
@Override
public String getPlanSQL() {
StatementBuilder buff = new StatementBuilder("MERGE INTO ");
buff.append(targetTable.getSQL()).append('(');
targetTable.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
......@@ -276,7 +276,7 @@ public class Merge extends CommandWithValues {
keys = idx.getColumns();
}
StatementBuilder buff = new StatementBuilder("UPDATE ");
buff.append(targetTable.getSQL()).append(" SET ");
targetTable.getSQL(buff.builder()).append(" SET ");
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL()).append("=?");
......
......@@ -390,7 +390,7 @@ public class MergeUsing extends Prepared {
@Override
public String getPlanSQL() {
StringBuilder builder = new StringBuilder("MERGE INTO ");
builder.append(targetTable.getSQL()).append('\n').append("USING ").append(query.getPlanSQL());
targetTable.getSQL(builder).append('\n').append("USING ").append(query.getPlanSQL());
// TODO add aliases and WHEN clauses to make plan SQL more like original SQL
return builder.toString();
}
......
......@@ -196,7 +196,7 @@ public class Replace extends CommandWithValues {
@Override
public String getPlanSQL() {
StatementBuilder buff = new StatementBuilder("REPLACE INTO ");
buff.append(table.getSQL()).append('(');
table.getSQL(buff.builder()).append('(');
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
......@@ -270,7 +270,7 @@ public class Replace extends CommandWithValues {
}
}
StatementBuilder buff = new StatementBuilder("UPDATE ");
buff.append(table.getSQL()).append(" SET ");
table.getSQL(buff.builder()).append(" SET ");
for (Column c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL()).append("=?");
......
......@@ -291,10 +291,10 @@ public class ScriptCommand extends ScriptBase {
}
if (TableType.TABLE == tableType) {
if (table.canGetRowCount()) {
String rowcount = "-- " +
table.getRowCountApproximation() +
" +/- SELECT COUNT(*) FROM " + table.getSQL();
add(rowcount, false);
StringBuilder builder = new StringBuilder("-- ").append(table.getRowCountApproximation())
.append(" +/- SELECT COUNT(*) FROM ");
table.getSQL(builder);
add(builder.toString(), false);
}
if (data) {
count = generateInsertValues(count, table);
......@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
Cursor cursor = index.find(session, null, null);
Column[] columns = table.getColumns();
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
buff.append(table.getSQL()).append('(');
table.getSQL(buff.builder()).append('(');
for (Column col : columns) {
buff.appendExceptFirst(", ");
Parser.quoteIdentifier(buff.builder(), col.getName());
......
......@@ -1474,8 +1474,8 @@ public class Select extends Query {
// since using a with statement will re-create the common table expression
// views.
} else {
buff.append("WITH RECURSIVE ")
.append(t.getSchema().getSQL()).append('.');
buff.append("WITH RECURSIVE ");
t.getSchema().getSQL(buff.builder()).append('.');
Parser.quoteIdentifier(buff.builder(), t.getName())
.append('(');
buff.resetCount();
......@@ -1483,7 +1483,8 @@ public class Select extends Query {
buff.appendExceptFirst(",");
buff.append(c.getName());
}
buff.append(") AS ").append(t.getSQL()).append('\n');
buff.append(") AS ");
t.getSQL(buff.builder()).append('\n');
}
}
}
......
......@@ -50,7 +50,7 @@ public class ConstraintCheck extends Constraint {
@Override
public String getCreateSQLForCopy(Table forTable, String quotedName) {
StringBuilder buff = new StringBuilder("ALTER TABLE ");
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
forTable.getSQL(buff).append(" ADD CONSTRAINT ");
if (forTable.isHidden()) {
buff.append("IF NOT EXISTS ");
}
......@@ -143,9 +143,8 @@ public class ConstraintCheck extends Constraint {
// don't check at startup
return;
}
StringBuilder builder = new StringBuilder().append("SELECT 1 FROM ")
.append(filter.getTable().getSQL())
.append(" WHERE NOT(");
StringBuilder builder = new StringBuilder().append("SELECT 1 FROM ");
filter.getTable().getSQL(builder).append(" WHERE NOT(");
expr.getSQL(builder).append(')');
String sql = builder.toString();
ResultInterface r = session.prepare(sql).query(1);
......
......@@ -80,8 +80,7 @@ public class ConstraintReferential extends Constraint {
public String getCreateSQLForCopy(Table forTable, Table forRefTable,
String quotedName, boolean internalIndex) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
String mainTable = forTable.getSQL();
buff.append(mainTable).append(" ADD CONSTRAINT ");
forTable.getSQL(buff.builder()).append(" ADD CONSTRAINT ");
if (forTable.isHidden()) {
buff.append("IF NOT EXISTS ");
}
......@@ -99,17 +98,17 @@ public class ConstraintReferential extends Constraint {
}
buff.append(')');
if (internalIndex && indexOwner && forTable == this.table) {
buff.append(" INDEX ").append(index.getSQL());
buff.append(" INDEX ");
index.getSQL(buff.builder());
}
buff.append(" REFERENCES ");
String quotedRefTable;
if (this.table == this.refTable) {
// self-referencing constraints: need to use new table
quotedRefTable = forTable.getSQL();
forTable.getSQL(buff.builder());
} else {
quotedRefTable = forRefTable.getSQL();
forRefTable.getSQL(buff.builder());
}
buff.append(quotedRefTable).append('(');
buff.append('(');
buff.resetCount();
for (IndexColumn r : refCols) {
buff.appendExceptFirst(", ");
......@@ -117,7 +116,8 @@ public class ConstraintReferential extends Constraint {
}
buff.append(')');
if (internalIndex && refIndexOwner && forTable == this.table) {
buff.append(" INDEX ").append(refIndex.getSQL());
buff.append(" INDEX ");
refIndex.getSQL(buff.builder());
}
if (deleteAction != ConstraintActionType.RESTRICT) {
buff.append(" ON DELETE ").append(deleteAction.getSqlName());
......@@ -139,12 +139,14 @@ public class ConstraintReferential extends Constraint {
*/
private String getShortDescription(Index searchIndex, SearchRow check) {
StatementBuilder buff = new StatementBuilder(getName());
buff.append(": ").append(table.getSQL()).append(" FOREIGN KEY(");
buff.append(": ");
table.getSQL(buff.builder()).append(" FOREIGN KEY(");
for (IndexColumn c : columns) {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
}
buff.append(") REFERENCES ").append(refTable.getSQL()).append('(');
buff.append(") REFERENCES ");
refTable.getSQL(buff.builder()).append('(');
buff.resetCount();
for (IndexColumn r : refColumns) {
buff.appendExceptFirst(", ");
......@@ -491,7 +493,8 @@ public class ConstraintReferential extends Constraint {
}
StatementBuilder buff = new StatementBuilder();
if (deleteAction == ConstraintActionType.CASCADE) {
buff.append("DELETE FROM ").append(table.getSQL());
buff.append("DELETE FROM ");
table.getSQL(buff.builder());
} else {
appendUpdate(buff);
}
......@@ -567,7 +570,8 @@ public class ConstraintReferential extends Constraint {
}
private void appendUpdate(StatementBuilder buff) {
buff.append("UPDATE ").append(table.getSQL()).append(" SET ");
buff.append("UPDATE ");
table.getSQL(buff.builder()).append(" SET ");
buff.resetCount();
for (IndexColumn c : columns) {
buff.appendExceptFirst(", ");
......@@ -622,7 +626,8 @@ public class ConstraintReferential extends Constraint {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
}
buff.append(" FROM ").append(table.getSQL()).append(" WHERE ");
buff.append(" FROM ");
table.getSQL(buff.builder()).append(" WHERE ");
buff.resetCount();
for (IndexColumn c : columns) {
buff.appendExceptFirst(" AND ");
......@@ -634,8 +639,8 @@ public class ConstraintReferential extends Constraint {
buff.appendExceptFirst(", ");
buff.append(c.getSQL());
}
buff.append(") C WHERE NOT EXISTS(SELECT 1 FROM ").
append(refTable.getSQL()).append(" P WHERE ");
buff.append(") C WHERE NOT EXISTS(SELECT 1 FROM ");
refTable.getSQL(buff.builder()).append(" P WHERE ");
buff.resetCount();
int i = 0;
for (IndexColumn c : columns) {
......
......@@ -46,7 +46,7 @@ public class ConstraintUnique extends Constraint {
private String getCreateSQLForCopy(Table forTable, String quotedName,
boolean internalIndex) {
StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
forTable.getSQL(buff.builder()).append(" ADD CONSTRAINT ");
if (forTable.isHidden()) {
buff.append("IF NOT EXISTS ");
}
......@@ -62,7 +62,8 @@ public class ConstraintUnique extends Constraint {
}
buff.append(')');
if (internalIndex && indexOwner && forTable == this.table) {
buff.append(" INDEX ").append(index.getSQL());
buff.append(" INDEX ");
index.getSQL(buff.builder());
}
return buff.toString();
}
......
......@@ -102,7 +102,9 @@ public class Comment extends DbObjectBase {
* @return the key name
*/
static String getKey(DbObject obj) {
return getTypeName(obj.getType()) + " " + obj.getSQL();
StringBuilder builder = new StringBuilder(getTypeName(obj.getType())).append(' ');
obj.getSQL(builder);
return builder.toString();
}
/**
......
......@@ -28,12 +28,16 @@ public class Domain extends DbObjectBase {
@Override
public String getDropSQL() {
return "DROP DOMAIN IF EXISTS " + getSQL();
StringBuilder builder = new StringBuilder("DROP DOMAIN IF EXISTS ");
return getSQL(builder).toString();
}
@Override
public String getCreateSQL() {
return "CREATE DOMAIN " + getSQL() + " AS " + column.getCreateSQL();
StringBuilder builder = new StringBuilder("CREATE DOMAIN ");
getSQL(builder).append(" AS ");
builder.append(column.getCreateSQL());
return builder.toString();
}
public Column getColumn() {
......
......@@ -135,18 +135,21 @@ public class Right extends DbObjectBase {
StringBuilder buff = new StringBuilder();
buff.append("GRANT ");
if (grantedRole != null) {
buff.append(grantedRole.getSQL());
grantedRole.getSQL(buff);
} else {
buff.append(getRights());
if (object != null) {
if (object instanceof Schema) {
buff.append(" ON SCHEMA ").append(object.getSQL());
buff.append(" ON SCHEMA ");
object.getSQL(buff);
} else if (object instanceof Table) {
buff.append(" ON ").append(object.getSQL());
buff.append(" ON ");
object.getSQL(buff);
}
}
}
buff.append(" TO ").append(grantee.getSQL());
buff.append(" TO ");
grantee.getSQL(buff);
return buff.toString();
}
......
......@@ -45,7 +45,7 @@ public class Role extends RightOwner {
if (ifNotExists) {
buff.append("IF NOT EXISTS ");
}
buff.append(getSQL());
getSQL(buff);
return buff.toString();
}
......
......@@ -393,8 +393,10 @@ public class Session extends SessionWithState implements TransactionStore.Rollba
localTempTables = database.newStringMap();
}
if (localTempTables.get(table.getName()) != null) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1,
table.getSQL()+" AS "+table.getName());
StringBuilder builder = new StringBuilder();
table.getSQL(builder).append(" AS ");
Parser.quoteIdentifier(table.getName());
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, builder.toString());
}
modificationId++;
localTempTables.put(table.getName(), table);
......
......@@ -50,7 +50,7 @@ public class Setting extends DbObjectBase {
@Override
public String getCreateSQL() {
StringBuilder buff = new StringBuilder("SET ");
buff.append(getSQL()).append(' ');
getSQL(buff).append(' ');
if (stringValue != null) {
buff.append(stringValue);
} else {
......
......@@ -157,7 +157,7 @@ public class User extends RightOwner {
*/
public String getCreateSQL(boolean password) {
StringBuilder buff = new StringBuilder("CREATE USER IF NOT EXISTS ");
buff.append(getSQL());
getSQL(buff);
if (comment != null) {
buff.append(" COMMENT ");
StringUtils.quoteStringSQL(buff, comment);
......
......@@ -59,13 +59,16 @@ public class UserAggregate extends DbObjectBase {
@Override
public String getDropSQL() {
return "DROP AGGREGATE IF EXISTS " + getSQL();
StringBuilder builder = new StringBuilder("DROP AGGREGATE IF EXISTS ");
return getSQL(builder).toString();
}
@Override
public String getCreateSQL() {
return "CREATE FORCE AGGREGATE " + getSQL() +
" FOR " + Parser.quoteIdentifier(className);
StringBuilder builder = new StringBuilder("CREATE FORCE AGGREGATE ");
getSQL(builder).append(" FOR ");
Parser.quoteIdentifier(builder, className);
return builder.toString();
}
@Override
......
......@@ -55,7 +55,7 @@ public class SequenceValue extends Expression {
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append("(NEXT VALUE FOR ");
return builder.append(sequence.getSQL()).append(')');
return sequence.getSQL(builder).append(')');
}
@Override
......
......@@ -93,12 +93,15 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* @return the exception
*/
protected DbException getDuplicateKeyException(String key) {
String sql = getName() + " ON " + table.getSQL() +
"(" + getColumnListSQL() + ")";
StringBuilder builder = new StringBuilder();
getSQL(builder).append(" ON ");
table.getSQL(builder).append('(');
builder.append(getColumnListSQL());
builder.append(')');
if (key != null) {
sql += " VALUES " + key;
builder.append(" VALUES ").append(key);
}
DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql);
DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, builder.toString());
e.setSource(this);
return e;
}
......@@ -426,7 +429,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
buff.append("IF NOT EXISTS ");
}
buff.append(quotedName);
buff.append(" ON ").append(targetTable.getSQL());
buff.append(" ON ");
targetTable.getSQL(buff);
if (comment != null) {
buff.append(" COMMENT ");
StringUtils.quoteStringSQL(buff, comment);
......
......@@ -229,7 +229,7 @@ public class PageBtreeLeaf extends PageBtree {
SearchRow delete = getRow(at);
if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
index.getSQL() + ": " + row);
index.getSQL(new StringBuilder()).append(": ").append(row).toString());
}
index.getPageStore().logUndo(this, data);
if (entryCount == 1) {
......
......@@ -139,11 +139,12 @@ public class PageDataIndex extends PageIndex {
}
public DbException getNewDuplicateKeyException() {
String sql = "PRIMARY KEY ON " + table.getSQL();
StringBuilder builder = new StringBuilder("PRIMARY KEY ON ");
table.getSQL(builder);
if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) {
sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")";
builder.append('(').append(indexColumns[mainIndexColumn].getSQL()).append(')');
}
DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, sql);
DbException e = DbException.get(ErrorCode.DUPLICATE_KEY_1, builder.toString());
e.setSource(this);
return e;
}
......@@ -478,7 +479,7 @@ public class PageDataIndex extends PageIndex {
@Override
public String getPlanSQL() {
return table.getSQL() + ".tableScan";
return table.getSQL(new StringBuilder()).append(".tableScan").toString();
}
int getMemoryPerPage() {
......
......@@ -416,7 +416,8 @@ public class PageDataLeaf extends PageData {
int i = find(key);
if (keys == null || keys[i] != key) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
index.getSQL() + ": " + key + " " + (keys == null ? -1 : keys[i]));
index.getSQL(new StringBuilder()).append(": ").append(key).append(' ')
.append(keys == null ? -1 : keys[i]).toString());
}
index.getPageStore().logUndo(this, data);
if (entryCount == 1) {
......
......@@ -193,7 +193,7 @@ public class ScanIndex extends BaseIndex {
@Override
public String getPlanSQL() {
return table.getSQL() + ".tableScan";
return table.getSQL(new StringBuilder()).append(".tableScan").toString();
}
}
......@@ -70,7 +70,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public String getPlanSQL() {
return table.getSQL() + ".tableScan";
return table.getSQL(new StringBuilder()).append(".tableScan").toString();
}
public void setMainIndexColumn(int mainIndexColumn) {
......@@ -116,16 +116,18 @@ public class MVPrimaryIndex extends BaseIndex {
try {
Value oldValue = map.putIfAbsent(key, ValueArray.get(row.getValueList()));
if (oldValue != null) {
String sql = "PRIMARY KEY ON " + table.getSQL();
StringBuilder builder = new StringBuilder("PRIMARY KEY ON ");
table.getSQL(builder);
if (mainIndexColumn >= 0 && mainIndexColumn < indexColumns.length) {
sql += "(" + indexColumns[mainIndexColumn].getSQL() + ")";
builder.append('(').append(indexColumns[mainIndexColumn].getSQL()).append(')');
}
int errorCode = ErrorCode.CONCURRENT_UPDATE_1;
if (map.get(key) != null) {
// committed
errorCode = ErrorCode.DUPLICATE_KEY_1;
}
DbException e = DbException.get(errorCode, sql + " " + oldValue);
builder.append(' ').append(oldValue);
DbException e = DbException.get(errorCode, builder.toString());
e.setSource(this);
throw e;
}
......@@ -154,8 +156,9 @@ public class MVPrimaryIndex extends BaseIndex {
try {
Value old = map.remove(ValueLong.get(row.getKey()));
if (old == null) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
getSQL() + ": " + row.getKey());
StringBuilder builder = new StringBuilder();
getSQL(builder).append(": ").append(row.getKey());
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, builder.toString());
}
} catch (IllegalStateException e) {
throw mvTable.convertException(e);
......@@ -194,8 +197,9 @@ public class MVPrimaryIndex extends BaseIndex {
try {
Value existing = map.put(ValueLong.get(key), ValueArray.get(newRow.getValueList()));
if (existing == null) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
getSQL() + ": " + key);
StringBuilder builder = new StringBuilder();
getSQL(builder).append(": ").append(key);
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, builder.toString());
}
} catch (IllegalStateException e) {
throw mvTable.convertException(e);
......@@ -286,7 +290,7 @@ public class MVPrimaryIndex extends BaseIndex {
return getRow(session, key, (ValueArray) v);
}
private Row getRow(Session session, long key, ValueArray array) {
private static Row getRow(Session session, long key, ValueArray array) {
Row row = session.createRow(array.getList(), 0);
row.setKey(key);
return row;
......
......@@ -231,8 +231,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
try {
Value old = map.remove(array);
if (old == null) {
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
getSQL() + ": " + row.getKey());
StringBuilder builder = new StringBuilder();
getSQL(builder).append(": ").append(row.getKey());
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, builder.toString());
}
} catch (IllegalStateException e) {
throw mvTable.convertException(e);
......
......@@ -183,9 +183,9 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
try {
Value old = map.remove(key);
if (old == null) {
old = map.remove(key);
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,
getSQL() + ": " + row.getKey());
StringBuilder builder = new StringBuilder();
getSQL(builder).append(": ").append(row.getKey());
throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, builder.toString());
}
} catch (IllegalStateException e) {
throw mvTable.convertException(e);
......
......@@ -38,7 +38,8 @@ public class Constant extends SchemaObjectBase {
@Override
public String getCreateSQL() {
StringBuilder builder = new StringBuilder().append("CREATE CONSTANT ").append(getSQL()).append(" VALUE ");
StringBuilder builder = new StringBuilder("CREATE CONSTANT ");
getSQL(builder).append(" VALUE ");
return value.getSQL(builder).toString();
}
......
......@@ -110,8 +110,10 @@ public class Schema extends DbObjectBase {
if (system) {
return null;
}
return "CREATE SCHEMA IF NOT EXISTS " +
getSQL() + " AUTHORIZATION " + owner.getSQL();
StringBuilder builder = new StringBuilder("CREATE SCHEMA IF NOT EXISTS ");
getSQL(builder).append(" AUTHORIZATION ");
owner.getSQL(builder);
return builder.toString();
}
@Override
......
......@@ -211,7 +211,8 @@ public class Sequence extends SchemaObjectBase {
if (getBelongsToTable()) {
return null;
}
return "DROP SEQUENCE IF EXISTS " + getSQL();
StringBuilder builder = new StringBuilder("DROP SEQUENCE IF EXISTS ");
return getSQL(builder).toString();
}
@Override
......@@ -223,7 +224,7 @@ public class Sequence extends SchemaObjectBase {
public synchronized String getCreateSQL() {
long v = writeWithMargin ? valueWithMargin : value;
StringBuilder buff = new StringBuilder("CREATE SEQUENCE ");
buff.append(getSQL()).append(" START WITH ").append(v);
getSQL(buff).append(" START WITH ").append(v);
if (increment != 1) {
buff.append(" INCREMENT BY ").append(increment);
}
......
......@@ -335,7 +335,8 @@ public class TriggerObject extends SchemaObjectBase {
buff.append(" AFTER ");
}
buff.append(getTypeNameList());
buff.append(" ON ").append(targetTable.getSQL());
buff.append(" ON ");
targetTable.getSQL(buff);
if (rowBased) {
buff.append(" FOR EACH ROW");
}
......
......@@ -490,7 +490,8 @@ public class Column {
buff.append(" NULL_TO_DEFAULT");
}
if (sequence != null) {
buff.append(" SEQUENCE ").append(sequence.getSQL());
buff.append(" SEQUENCE ");
sequence.getSQL(buff);
}
if (selectivity != 0) {
buff.append(" SELECTIVITY ").append(selectivity);
......
......@@ -79,7 +79,9 @@ public abstract class TableBase extends Table {
@Override
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL() + " CASCADE";
StringBuilder builder = new StringBuilder("DROP TABLE IF EXISTS ");
getSQL(builder).append(" CASCADE");
return builder.toString();
}
@Override
......@@ -106,7 +108,7 @@ public abstract class TableBase extends Table {
if (isHidden) {
buff.append("IF NOT EXISTS ");
}
buff.append(getSQL());
getSQL(buff.builder());
if (comment != null) {
buff.append(" COMMENT ");
StringUtils.quoteStringSQL(buff.builder(), comment);
......
......@@ -791,10 +791,10 @@ public class TableFilter implements ColumnResolver {
return builder;
}
if (table.isView() && ((TableView) table).isRecursive()) {
builder.append(table.getSchema().getSQL()).append('.');
table.getSchema().getSQL(builder).append('.');
Parser.quoteIdentifier(builder, table.getName());
} else {
builder.append(table.getSQL());
table.getSQL(builder);
}
if (table.isView() && ((TableView) table).isInvalid()) {
throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, table.getName(), "not compiled");
......
......@@ -354,7 +354,8 @@ public class TableLink extends Table {
@Override
public String getDropSQL() {
return "DROP TABLE IF EXISTS " + getSQL();
StringBuilder builder = new StringBuilder("DROP TABLE IF EXISTS ");
return getSQL(builder).toString();
}
@Override
......@@ -368,7 +369,8 @@ public class TableLink extends Table {
}
buff.append("TEMPORARY ");
}
buff.append("LINKED TABLE ").append(getSQL());
buff.append("LINKED TABLE ");
getSQL(buff);
if (comment != null) {
buff.append(" COMMENT ");
StringUtils.quoteStringSQL(buff, comment);
......
......@@ -5,6 +5,7 @@
*/
package org.h2.table;
import org.h2.command.Parser;
import org.h2.command.ddl.CreateSynonymData;
import org.h2.engine.Session;
import org.h2.message.DbException;
......@@ -67,12 +68,18 @@ public class TableSynonym extends SchemaObjectBase {
@Override
public String getCreateSQL() {
return "CREATE SYNONYM " + getSQL() + " FOR " + data.synonymForSchema.getName() + "." + data.synonymFor;
StringBuilder builder = new StringBuilder("CREATE SYNONYM ");
getSQL(builder).append(" FOR ");
Parser.quoteIdentifier(data.synonymForSchema.getName());
builder.append('.');
Parser.quoteIdentifier(data.synonymFor);
return builder.toString();
}
@Override
public String getDropSQL() {
return "DROP SYNONYM " + getSQL();
StringBuilder builder = new StringBuilder("DROP SYNONYM ");
return getSQL(builder).toString();
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论