use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserDQL method readSQLFunction.
ExpressionOrException readSQLFunction(FunctionSQL function, boolean preferToThrow) {
// End of VoltDB extension
read();
int position = getPosition();
short[] parseList = function.parseList;
if (parseList.length == 0) {
// A VoltDB extension to avoid using exceptions for flow control.
return new ExpressionOrException(function);
/* disable 1 line ...
return function;
... disabled 1 line */
// End of VoltDB extension
}
HsqlArrayList exprList = new HsqlArrayList();
// A VoltDB extension to avoid using exceptions for flow control.
HsqlException e = null;
int prevParamCount = compileContext.parameters.size();
try {
e = readExpression(exprList, parseList, 0, parseList.length, false, false);
} catch (HsqlException caught) {
e = caught;
}
if (e != null) {
if (function.parseListAlt == null) {
if (!preferToThrow) {
return new ExpressionOrException(e);
}
// End of VoltDB extension
throw e;
}
rewind(position);
// Discard parsed parameters along with the token rewinding.
for (int i = compileContext.parameters.size() - 1; i >= prevParamCount; i--) {
compileContext.parameters.remove(i);
}
parseList = function.parseListAlt;
exprList = new HsqlArrayList();
// A VoltDB extension to avoid using exceptions for flow control.
HsqlException e2 = readExpression(exprList, parseList, 0, parseList.length, false, false);
if (e2 != null) {
// standard) alternative syntax that also failed.
if (!preferToThrow) {
return new ExpressionOrException(e);
}
throw e;
}
/* disable 1 line ...
readExpression(exprList, parseList, 0, parseList.length, false);
... disabled 1 line */
// End of VoltDB extension
}
Expression[] expr = new Expression[exprList.size()];
exprList.toArray(expr);
function.setArguments(expr);
// A VoltDB extension to avoid using exceptions for flow control.
return new ExpressionOrException(function.getFunctionExpression());
/* disable 1 line ...
return function.getFunctionExpression();
... disabled 1 line */
// End of VoltDB extension
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserRoutine method readCase.
private Statement readCase(Routine routine, StatementCompound context) {
HsqlArrayList list = new HsqlArrayList();
Expression condition = null;
Statement statement;
Statement[] statements;
readThis(Tokens.CASE);
if (token.tokenType == Tokens.WHEN) {
list = readCaseWhen(routine, context);
} else {
list = readSimpleCaseWhen(routine, context);
}
if (token.tokenType == Tokens.ELSE) {
read();
condition = Expression.EXPR_TRUE;
statement = new StatementSimple(StatementTypes.CONDITION, condition);
list.add(statement);
statements = readSQLProcedureStatementList(routine, context);
for (int i = 0; i < statements.length; i++) {
list.add(statements[i]);
}
}
readThis(Tokens.END);
readThis(Tokens.CASE);
statements = new Statement[list.size()];
list.toArray(statements);
StatementCompound result = new StatementCompound(StatementTypes.IF, null);
result.setStatements(statements);
return result;
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserRoutine method readIf.
private Statement readIf(Routine routine, StatementCompound context) {
HsqlArrayList list = new HsqlArrayList();
RangeVariable[] rangeVariables = context == null ? routine.getParameterRangeVariables() : context.getRangeVariables();
HsqlList unresolved = null;
readThis(Tokens.IF);
Expression condition = XreadBooleanValueExpression();
unresolved = condition.resolveColumnReferences(rangeVariables, rangeVariables.length, unresolved, false);
ExpressionColumn.checkColumnsResolved(unresolved);
unresolved = null;
condition.resolveTypes(session, null);
Statement statement = new StatementSimple(StatementTypes.CONDITION, condition);
list.add(statement);
readThis(Tokens.THEN);
Statement[] statements = readSQLProcedureStatementList(routine, context);
for (int i = 0; i < statements.length; i++) {
list.add(statements[i]);
}
while (token.tokenType == Tokens.ELSEIF) {
read();
condition = XreadBooleanValueExpression();
unresolved = condition.resolveColumnReferences(rangeVariables, rangeVariables.length, unresolved, false);
ExpressionColumn.checkColumnsResolved(unresolved);
unresolved = null;
condition.resolveTypes(session, null);
statement = new StatementSimple(StatementTypes.CONDITION, condition);
list.add(statement);
readThis(Tokens.THEN);
statements = readSQLProcedureStatementList(routine, context);
for (int i = 0; i < statements.length; i++) {
list.add(statements[i]);
}
}
if (token.tokenType == Tokens.ELSE) {
read();
condition = Expression.EXPR_TRUE;
statement = new StatementSimple(StatementTypes.CONDITION, condition);
list.add(statement);
statements = readSQLProcedureStatementList(routine, context);
for (int i = 0; i < statements.length; i++) {
list.add(statements[i]);
}
}
readThis(Tokens.END);
readThis(Tokens.IF);
statements = new Statement[list.size()];
list.toArray(statements);
StatementCompound result = new StatementCompound(StatementTypes.IF, null);
result.setStatements(statements);
return result;
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserDDL method compileCreateTable.
StatementSchema compileCreateTable(int type) {
HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.TABLE);
HsqlArrayList tempConstraints = new HsqlArrayList();
name.setSchemaIfNull(session.getCurrentSchemaHsqlName());
Table table = TableUtil.newTable(database, type, name);
if (token.tokenType == Tokens.AS) {
return readTableAsSubqueryDefinition(table);
}
int position = getPosition();
readThis(Tokens.OPENBRACKET);
{
Constraint c = new Constraint(null, true, null, Constraint.TEMP);
tempConstraints.add(c);
}
boolean start = true;
boolean startPart = true;
boolean end = false;
while (!end) {
switch(token.tokenType) {
case Tokens.LIKE:
{
ColumnSchema[] likeColumns = readLikeTable(table);
for (int i = 0; i < likeColumns.length; i++) {
table.addColumn(likeColumns[i]);
}
start = false;
startPart = false;
break;
}
case Tokens.CONSTRAINT:
case Tokens.PRIMARY:
case Tokens.FOREIGN:
// A VoltDB extension to support the assume unique attribute
case Tokens.ASSUMEUNIQUE:
// End of VoltDB extension
case Tokens.UNIQUE:
case Tokens.CHECK:
// A VoltDB extension to support LIMIT PARTITION ROWS
case Tokens.LIMIT:
// End of VoltDB extension
if (!startPart) {
throw unexpectedToken();
}
readConstraint(table, tempConstraints);
start = false;
startPart = false;
break;
case Tokens.COMMA:
if (startPart) {
throw unexpectedToken();
}
read();
startPart = true;
break;
case Tokens.CLOSEBRACKET:
read();
end = true;
break;
default:
if (!startPart) {
throw unexpectedToken();
}
checkIsSchemaObjectName();
HsqlName hsqlName = database.nameManager.newColumnHsqlName(name, token.tokenString, isDelimitedIdentifier());
read();
ColumnSchema newcolumn = readColumnDefinitionOrNull(table, hsqlName, tempConstraints);
if (newcolumn == null) {
if (start) {
rewind(position);
return readTableAsSubqueryDefinition(table);
} else {
throw Error.error(ErrorCode.X_42000);
}
}
table.addColumn(newcolumn);
start = false;
startPart = false;
}
}
if (token.tokenType == Tokens.ON) {
if (!table.isTemp()) {
throw unexpectedToken();
}
read();
readThis(Tokens.COMMIT);
if (token.tokenType == Tokens.DELETE) {
} else if (token.tokenType == Tokens.PRESERVE) {
table.persistenceScope = TableBase.SCOPE_SESSION;
}
read();
readThis(Tokens.ROWS);
}
Object[] args = new Object[] { table, tempConstraints, null };
String sql = getLastPart();
return new StatementSchema(sql, StatementTypes.CREATE_TABLE, args, null, null);
}
use of org.hsqldb_voltpatches.lib.HsqlArrayList in project voltdb by VoltDB.
the class ParserDDL method compileAlterDomain.
Statement compileAlterDomain() {
HsqlName schema = session.getSchemaHsqlName(token.namePrefix);
Type domain = database.schemaManager.getDomain(token.tokenString, schema.name, true);
read();
switch(token.tokenType) {
case Tokens.RENAME:
{
read();
readThis(Tokens.TO);
return compileRenameObject(domain.getName(), SchemaObject.DOMAIN);
}
case Tokens.DROP:
{
read();
if (token.tokenType == Tokens.DEFAULT) {
read();
return compileAlterDomainDropDefault(domain);
} else if (token.tokenType == Tokens.CONSTRAINT) {
read();
checkIsSchemaObjectName();
HsqlName name = database.schemaManager.getSchemaObjectName(domain.getSchemaName(), token.tokenString, SchemaObject.CONSTRAINT, true);
read();
return compileAlterDomainDropConstraint(domain, name);
} else {
throw unexpectedToken();
}
}
case Tokens.SET:
{
read();
readThis(Tokens.DEFAULT);
Expression e = readDefaultClause(domain);
return compileAlterDomainSetDefault(domain, e);
}
case Tokens.ADD:
{
read();
if (token.tokenType == Tokens.CONSTRAINT || token.tokenType == Tokens.CHECK) {
HsqlArrayList tempConstraints = new HsqlArrayList();
readConstraint(domain, tempConstraints);
Constraint c = (Constraint) tempConstraints.get(0);
return compileAlterDomainAddConstraint(domain, c);
}
}
}
throw unexpectedToken();
}
Aggregations