use of org.hsqldb_voltpatches.lib.HsqlList in project voltdb by VoltDB.
the class ParserRoutine method readReturnValue.
private Statement readReturnValue(Routine routine, StatementCompound context) {
Expression e = XreadValueExpressionOrNull();
if (e == null) {
checkIsValue();
if (token.tokenValue == null) {
e = new ExpressionValue(null, null);
}
}
RangeVariable[] rangeVars = routine.getParameterRangeVariables();
if (context != null) {
rangeVars = context.getRangeVariables();
}
HsqlList list = e.resolveColumnReferences(rangeVars, rangeVars.length, null, false);
ExpressionColumn.checkColumnsResolved(list);
e.resolveTypes(session, null);
return new StatementSimple(StatementTypes.RETURN, e);
}
use of org.hsqldb_voltpatches.lib.HsqlList in project voltdb by VoltDB.
the class ParserDML method compileCallStatement.
/**
* Retrieves a CALL Statement from this parse context.
*/
// to do call argument name and type resolution
StatementDMQL compileCallStatement(RangeVariable[] outerRanges, boolean isStrictlyProcedure) {
read();
if (isIdentifier()) {
checkValidCatalogName(token.namePrePrefix);
RoutineSchema routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(token.tokenString, session.getSchemaName(token.namePrefix), SchemaObject.PROCEDURE);
if (routineSchema != null) {
read();
HsqlArrayList list = new HsqlArrayList();
readThis(Tokens.OPENBRACKET);
if (token.tokenType == Tokens.CLOSEBRACKET) {
read();
} else {
while (true) {
Expression e = XreadValueExpression();
list.add(e);
if (token.tokenType == Tokens.COMMA) {
read();
} else {
readThis(Tokens.CLOSEBRACKET);
break;
}
}
}
Expression[] arguments = new Expression[list.size()];
list.toArray(arguments);
Routine routine = routineSchema.getSpecificRoutine(arguments.length);
HsqlList unresolved = null;
for (int i = 0; i < arguments.length; i++) {
Expression e = arguments[i];
if (e.isParam()) {
e.setAttributesAsColumn(routine.getParameter(i), routine.getParameter(i).isWriteable());
} else {
int paramMode = routine.getParameter(i).getParameterMode();
unresolved = arguments[i].resolveColumnReferences(outerRanges, unresolved);
if (paramMode != SchemaObject.ParameterModes.PARAM_IN) {
if (e.getType() != OpTypes.VARIABLE) {
throw Error.error(ErrorCode.X_42603);
}
}
}
}
ExpressionColumn.checkColumnsResolved(unresolved);
for (int i = 0; i < arguments.length; i++) {
arguments[i].resolveTypes(session, null);
}
StatementDMQL cs = new StatementProcedure(session, routine, arguments, compileContext);
return cs;
}
}
if (isStrictlyProcedure) {
throw Error.error(ErrorCode.X_42501, token.tokenString);
}
Expression expression = this.XreadValueExpression();
HsqlList unresolved = expression.resolveColumnReferences(outerRanges, null);
ExpressionColumn.checkColumnsResolved(unresolved);
expression.resolveTypes(session, null);
// expression.paramMode = PARAM_OUT;
StatementDMQL cs = new StatementProcedure(session, expression, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.HsqlList in project voltdb by VoltDB.
the class ParserDML method compileInsertStatement.
/**
* Retrieves an INSERT Statement from this parse context.
*/
StatementDMQL compileInsertStatement(RangeVariable[] outerRanges) {
read();
readThis(Tokens.INTO);
boolean[] columnCheckList;
int[] columnMap;
int colCount;
Table table = readTableName();
boolean overridingUser = false;
boolean overridingSystem = false;
int enforcedDefaultIndex = table.getIdentityColumnIndex();
boolean assignsToIdentity = false;
columnCheckList = null;
columnMap = table.getColumnMap();
colCount = table.getColumnCount();
int position = getPosition();
if (!table.isInsertable()) {
throw Error.error(ErrorCode.X_42545);
}
Table baseTable = table.getBaseTable();
switch(token.tokenType) {
case Tokens.DEFAULT:
{
read();
readThis(Tokens.VALUES);
Expression insertExpression = new Expression(OpTypes.ROW, new Expression[] {});
insertExpression = new Expression(OpTypes.TABLE, new Expression[] { insertExpression });
columnCheckList = table.getNewColumnCheckList();
for (int i = 0; i < table.colDefaults.length; i++) {
if (table.colDefaults[i] == null && table.identityColumn != i) {
throw Error.error(ErrorCode.X_42544);
}
}
StatementDMQL cs = new StatementInsert(session, table, columnMap, insertExpression, columnCheckList, compileContext);
return cs;
}
case Tokens.OPENBRACKET:
{
int brackets = readOpenBrackets();
if (brackets == 1) {
boolean isQuery = false;
switch(token.tokenType) {
case Tokens.WITH:
case Tokens.SELECT:
case Tokens.TABLE:
{
rewind(position);
isQuery = true;
break;
}
default:
}
if (isQuery) {
break;
}
OrderedHashSet columnNames = new OrderedHashSet();
readSimpleColumnNames(columnNames, table);
readThis(Tokens.CLOSEBRACKET);
colCount = columnNames.size();
columnMap = table.getColumnIndexes(columnNames);
if (token.tokenType != Tokens.VALUES && token.tokenType != Tokens.OVERRIDING) {
break;
}
// $FALL-THROUGH$
} else {
rewind(position);
break;
}
}
// $FALL-THROUGH$
case Tokens.OVERRIDING:
{
if (token.tokenType == Tokens.OVERRIDING) {
read();
if (token.tokenType == Tokens.USER) {
read();
overridingUser = true;
} else if (token.tokenType == Tokens.SYSTEM) {
read();
overridingSystem = true;
} else {
unexpectedToken();
}
}
if (token.tokenType != Tokens.VALUES) {
break;
}
}
// $FALL-THROUGH$
case Tokens.VALUES:
{
read();
columnCheckList = table.getColumnCheckList(columnMap);
Expression insertExpressions = XreadContextuallyTypedTable(colCount);
HsqlList unresolved = insertExpressions.resolveColumnReferences(outerRanges, null);
ExpressionColumn.checkColumnsResolved(unresolved);
insertExpressions.resolveTypes(session, null);
setParameterTypes(insertExpressions, table, columnMap);
if (table != baseTable) {
int[] baseColumnMap = table.getBaseTableColumnMap();
int[] newColumnMap = new int[columnMap.length];
ArrayUtil.projectRow(baseColumnMap, columnMap, newColumnMap);
columnMap = newColumnMap;
}
Expression[] rowList = insertExpressions.nodes;
for (int j = 0; j < rowList.length; j++) {
Expression[] rowArgs = rowList[j].nodes;
for (int i = 0; i < rowArgs.length; i++) {
Expression e = rowArgs[i];
if (enforcedDefaultIndex == columnMap[i]) {
assignsToIdentity = true;
if (e.getType() != OpTypes.DEFAULT) {
if (table.identitySequence.isAlways()) {
if (!overridingUser && !overridingSystem) {
throw Error.error(ErrorCode.X_42543);
}
} else {
/*
if (overridingUser) {
throw Trace.error(
Trace.SQL_DEFAULT_CLAUSE_REQUITED);
}
*/
}
}
}
if (e.isParam()) {
e.setAttributesAsColumn(table.getColumn(columnMap[i]), true);
} else if (e.getType() == OpTypes.DEFAULT) {
if (table.colDefaults[i] == null && table.identityColumn != columnMap[i]) {
throw Error.error(ErrorCode.X_42544);
}
}
}
}
if (!assignsToIdentity && (overridingUser || overridingSystem)) {
unexpectedTokenRequire(Tokens.T_OVERRIDING);
}
StatementDMQL cs = new StatementInsert(session, table, columnMap, insertExpressions, columnCheckList, compileContext);
return cs;
}
case Tokens.WITH:
case Tokens.SELECT:
case Tokens.TABLE:
{
break;
}
default:
{
throw unexpectedToken();
}
}
columnCheckList = table.getColumnCheckList(columnMap);
QueryExpression queryExpression = XreadQueryExpression();
queryExpression.setAsTopLevel();
queryExpression.resolve(session, outerRanges);
if (colCount != queryExpression.getColumnCount()) {
throw Error.error(ErrorCode.X_42546);
}
if (table != baseTable) {
int[] baseColumnMap = table.getBaseTableColumnMap();
int[] newColumnMap = new int[columnMap.length];
ArrayUtil.projectRow(baseColumnMap, columnMap, newColumnMap);
columnMap = newColumnMap;
}
if (enforcedDefaultIndex != -1 && ArrayUtil.find(columnMap, enforcedDefaultIndex) > -1) {
if (table.identitySequence.isAlways()) {
if (!overridingUser && !overridingSystem) {
throw Error.error(ErrorCode.X_42543);
}
} else {
/*
if (overridingUser) {
throw Trace.error(
Trace.SQL_DEFAULT_CLAUSE_REQUITED);
}
*/
}
} else if (overridingUser || overridingSystem) {
unexpectedTokenRequire(Tokens.T_OVERRIDING);
}
StatementDMQL cs = new StatementInsert(session, table, columnMap, columnCheckList, queryExpression, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.HsqlList in project voltdb by VoltDB.
the class ParserDML method compileUpdateStatement.
/**
* Creates an UPDATE-type Statement from this parse context.
*/
StatementDMQL compileUpdateStatement(RangeVariable[] outerRanges) {
read();
Expression[] updateExpressions;
int[] columnMap;
boolean[] columnCheckList;
OrderedHashSet colNames = new OrderedHashSet();
HsqlArrayList exprList = new HsqlArrayList();
RangeVariable[] rangeVariables = { readSimpleRangeVariable(StatementTypes.UPDATE_WHERE) };
Table table = rangeVariables[0].rangeTable;
Table baseTable = table.getBaseTable();
readThis(Tokens.SET);
readSetClauseList(rangeVariables, colNames, exprList);
columnMap = table.getColumnIndexes(colNames);
columnCheckList = table.getColumnCheckList(columnMap);
updateExpressions = new Expression[exprList.size()];
exprList.toArray(updateExpressions);
Expression condition = null;
if (token.tokenType == Tokens.WHERE) {
read();
condition = XreadBooleanValueExpression();
HsqlList unresolved = condition.resolveColumnReferences(outerRanges, null);
unresolved = Expression.resolveColumnSet(rangeVariables, unresolved, null);
ExpressionColumn.checkColumnsResolved(unresolved);
condition.resolveTypes(session, null);
if (condition.isParam()) {
condition.dataType = Type.SQL_BOOLEAN;
} else if (condition.getDataType() != Type.SQL_BOOLEAN) {
throw Error.error(ErrorCode.X_42568);
}
}
resolveUpdateExpressions(table, rangeVariables, columnMap, updateExpressions, outerRanges);
if (baseTable != null && table != baseTable) {
QuerySpecification select = ((TableDerived) table).getQueryExpression().getMainSelect();
if (condition != null) {
condition = condition.replaceColumnReferences(rangeVariables[0], select.exprColumns);
}
rangeVariables[0] = new RangeVariable(select.rangeVariables[0]);
condition = ExpressionLogical.andExpressions(select.queryCondition, condition);
}
if (condition != null) {
RangeVariableResolver resolver = new RangeVariableResolver(rangeVariables, condition, compileContext);
resolver.processConditions();
rangeVariables = resolver.rangeVariables;
}
if (baseTable != null && table != baseTable) {
int[] baseColumnMap = table.getBaseTableColumnMap();
int[] newColumnMap = new int[columnMap.length];
ArrayUtil.projectRow(baseColumnMap, columnMap, newColumnMap);
columnMap = newColumnMap;
}
StatementDMQL cs = new StatementDML(session, table, rangeVariables, columnMap, updateExpressions, columnCheckList, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.HsqlList in project voltdb by VoltDB.
the class ParserDQL method XreadRowValueExpressionList.
private SubQuery XreadRowValueExpressionList() {
compileContext.subQueryDepth++;
Expression e = XreadRowValueExpressionListBody();
HsqlList unresolved = e.resolveColumnReferences(RangeVariable.emptyArray, null);
ExpressionColumn.checkColumnsResolved(unresolved);
e.resolveTypes(session, null);
e.prepareTable(session, null, e.nodes[0].nodes.length);
SubQuery sq = new SubQuery(database, compileContext.subQueryDepth, e, OpTypes.TABLE);
sq.prepareTable(session);
compileContext.subQueryList.add(sq);
compileContext.subQueryDepth--;
return sq;
}
Aggregations