try {
value = expressions[0].getValue(session);
} catch (HsqlException e) {}
if (value instanceof Result) {
Result result = (Result) value;
if (result.isData()) {
Object[] data =
(Object[]) result.getNavigator().getNext();
boolean single = !result.getNavigator().next();
if (single && data != null && data[0] != null) {
value = data[0];
result.getNavigator().close();
} else {
result.getNavigator().close();
return Result.newErrorResult(
Error.error(ErrorCode.X_22009), sql);
}
} else {
return Result.newErrorResult(
Error.error(ErrorCode.X_22009), sql);
}
} else {
if (value == null) {
return Result.newErrorResult(
Error.error(ErrorCode.X_22009), sql);
}
}
long seconds = ((IntervalSecondData) value).getSeconds();
if (-DTIType.timezoneSecondsLimit <= seconds
&& seconds <= DTIType.timezoneSecondsLimit) {
session.setZoneSeconds((int) seconds);
return Result.updateZeroResult;
}
return Result.newErrorResult(Error.error(ErrorCode.X_22009),
sql);
}
case StatementTypes.SET_NAMES :
return Result.updateZeroResult;
case StatementTypes.SET_PATH :
return Result.updateZeroResult;
case StatementTypes.SET_ROLE : {
String name;
Grantee role = null;
try {
name = (String) expressions[0].getValue(session);
if (name != null) {
name = (String) Type.SQL_VARCHAR.trim(session, name,
' ', true, true);
role = session.database.granteeManager.getRole(name);
}
} catch (HsqlException e) {
return Result.newErrorResult(
Error.error(ErrorCode.X_0P000), sql);
}
if (session.isInMidTransaction()) {
return Result.newErrorResult(
Error.error(ErrorCode.X_25001), sql);
}
if (role == null) {
session.setRole(null);
}
if (session.getGrantee().hasRole(role)) {
session.setRole(role);
return Result.updateZeroResult;
} else {
return Result.newErrorResult(
Error.error(ErrorCode.X_0P000), sql);
}
}
case StatementTypes.SET_SCHEMA : {
String name;
HsqlName schema;
try {
if (expressions == null) {
name = ((HsqlName) parameters[0]).name;
} else {
name = (String) expressions[0].getValue(session);
}
name = (String) Type.SQL_VARCHAR.trim(session, name, ' ',
true, true);
schema =
session.database.schemaManager.getSchemaHsqlName(name);
session.setSchema(schema.name);
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.SET_SESSION_AUTHORIZATION : {
if (session.isInMidTransaction()) {
return Result.newErrorResult(
Error.error(ErrorCode.X_25001), sql);
}
try {
String user;
String password = null;
user = (String) expressions[0].getValue(session);
user = (String) Type.SQL_VARCHAR.trim(session, user, ' ',
true, true);
if (expressions[1] != null) {
password = (String) expressions[1].getValue(session);
}
User userObject;
if (password == null) {
userObject = session.database.userManager.get(user);
} else {
userObject =
session.database.getUserManager().getUser(user,
password);
}
if (userObject == null) {
throw Error.error(ErrorCode.X_28501);
}
sql = userObject.getConnectUserSQL();
if (userObject == session.getGrantee()) {
return Result.updateZeroResult;
}
if (session.getGrantee().canChangeAuthorisation()) {
session.setUser((User) userObject);
session.setRole(null);
session.resetSchema();
return Result.updateZeroResult;
}
/** @todo may need different error code */
throw Error.error(ErrorCode.X_28000);
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.SET_SESSION_CHARACTERISTICS : {
try {
if (parameters[0] != null) {
boolean readonly =
((Boolean) parameters[0]).booleanValue();
session.setReadOnlyDefault(readonly);
}
if (parameters[1] != null) {
int level = ((Integer) parameters[1]).intValue();
session.setIsolationDefault(level);
}
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.SET_COLLATION :
return Result.updateZeroResult;
case StatementTypes.SET_TRANSFORM_GROUP :
return Result.updateZeroResult;
case StatementTypes.START_TRANSACTION :
startTransaction = true;
// fall through
case StatementTypes.SET_TRANSACTION : {
try {
if (parameters[0] != null) {
boolean readonly =
((Boolean) parameters[0]).booleanValue();
session.setReadOnly(readonly);
}
if (parameters[1] != null) {
int level = ((Integer) parameters[1]).intValue();
session.setIsolation(level);
}
if (startTransaction) {
session.startTransaction();
}
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
//
case StatementTypes.SET_SESSION_AUTOCOMMIT : {
boolean mode = ((Boolean) parameters[0]).booleanValue();
try {
session.setAutoCommit(mode);
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.DECLARE_VARIABLE : {
ColumnSchema[] variables = (ColumnSchema[]) parameters[0];
try {
for (int i = 0; i < variables.length; i++) {
session.sessionContext.addSessionVariable(
variables[i]);
}
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.SET_SESSION_RESULT_MAX_ROWS : {
int size = ((Integer) parameters[0]).intValue();
session.setSQLMaxRows(size);
return Result.updateZeroResult;
}
case StatementTypes.SET_SESSION_RESULT_MEMORY_ROWS : {
int size = ((Integer) parameters[0]).intValue();
session.setResultMemoryRowCount(size);
return Result.updateZeroResult;
}
case StatementTypes.SET_SESSION_SQL_IGNORECASE : {
try {
boolean mode = ((Boolean) parameters[0]).booleanValue();
session.setIgnoreCase(mode);
return Result.updateZeroResult;
} catch (HsqlException e) {
return Result.newErrorResult(e, sql);
}
}
case StatementTypes.DECLARE_SESSION_TABLE : {
Table table = (Table) parameters[0];
HsqlArrayList tempConstraints = (HsqlArrayList) parameters[1];
StatementDMQL statement = (StatementDMQL) parameters[2];
try {
if (tempConstraints != null) {
table =
ParserDDL.addTableConstraintDefinitions(session,
table, tempConstraints, null, false);
}
table.compile(session, null);
session.addSessionTable(table);
if (statement != null) {
Result result = statement.execute(session);
table.insertIntoTable(session, result);
}
if (table.hasLobColumn) {