return Result.newSingleColumnStringResult("OPERATION",
describe(session));
}
StatementSchema cs;
Result result = statements[0].execute(session);
HsqlArrayList constraints = new HsqlArrayList();
if (statements.length == 1 || result.isError()) {
return result;
}
HsqlName oldSessionSchema = session.getCurrentSchemaHsqlName();
for (int i = 1; i < statements.length; i++) {
try {
session.setSchema(schemaName.name);
} catch (HsqlException e) {}
statements[i].setSchemaHsqlName(schemaName);
session.parser.reset(statements[i].getSQL());
try {
session.parser.read();
switch (statements[i].getType()) {
case StatementTypes.GRANT :
case StatementTypes.GRANT_ROLE :
result = statements[i].execute(session);
break;
case StatementTypes.CREATE_TABLE :
cs = session.parser.compileCreate();
cs.isSchemaDefinition = true;
cs.setSchemaHsqlName(schemaName);
if (session.parser.token.tokenType
!= Tokens.X_ENDPARSE) {
throw session.parser.unexpectedToken();
}
result = cs.execute(session);
constraints.addAll((HsqlArrayList) cs.arguments[1]);
((HsqlArrayList) cs.arguments[1]).clear();
break;
case StatementTypes.CREATE_ROLE :
case StatementTypes.CREATE_SEQUENCE :
case StatementTypes.CREATE_TYPE :
case StatementTypes.CREATE_CHARACTER_SET :
case StatementTypes.CREATE_COLLATION :
result = statements[i].execute(session);
break;
case StatementTypes.CREATE_INDEX :
case StatementTypes.CREATE_TRIGGER :
case StatementTypes.CREATE_VIEW :
case StatementTypes.CREATE_DOMAIN :
case StatementTypes.CREATE_ROUTINE :
cs = session.parser.compileCreate();
cs.isSchemaDefinition = true;
cs.setSchemaHsqlName(schemaName);
if (session.parser.token.tokenType
!= Tokens.X_ENDPARSE) {
throw session.parser.unexpectedToken();
}
result = cs.execute(session);
break;
case StatementTypes.CREATE_ASSERTION :
case StatementTypes.CREATE_TRANSFORM :
case StatementTypes.CREATE_TRANSLATION :
case StatementTypes.CREATE_CAST :
case StatementTypes.CREATE_ORDERING :
throw session.parser.unsupportedFeature();
default :
throw Error.runtimeError(ErrorCode.U_S0500, "");
}
if (result.isError()) {
break;
}
} catch (HsqlException e) {
result = Result.newErrorResult(e, statements[i].getSQL());
}
}
if (!result.isError()) {
try {
for (int i = 0; i < constraints.size(); i++) {
Constraint c = (Constraint) constraints.get(i);
Table table =
session.database.schemaManager.getUserTable(session,
c.core.refTableName);
ParserDDL.addForeignKey(session, table, c, null);
}
} catch (HsqlException e) {
result = Result.newErrorResult(e, sql);
}
}
if (result.isError()) {
try {
session.database.schemaManager.dropSchema(schemaName.name,
true);
session.database.logger.writeToLog(
session, getDropSchemaStatement(schemaName));