use of org.hsqldb_voltpatches.lib.OrderedHashSet 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.OrderedHashSet 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.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method XreadUnionCorrespondingClause.
void XreadUnionCorrespondingClause(QueryExpression queryExpression) {
if (token.tokenType == Tokens.CORRESPONDING) {
read();
queryExpression.setUnionCorresponding();
if (token.tokenType == Tokens.BY) {
read();
OrderedHashSet names = readColumnNames(false);
queryExpression.setUnionCorrespondingColumns(names);
}
}
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method compileCursorSpecification.
/**
* Retrieves a SELECT or other query expression Statement from this parse context.
*/
StatementDMQL compileCursorSpecification() {
QueryExpression queryExpression = XreadQueryExpression();
queryExpression.setAsTopLevel();
queryExpression.resolve(session);
if (token.tokenType == Tokens.FOR) {
read();
if (token.tokenType == Tokens.READ) {
read();
readThis(Tokens.ONLY);
} else {
readThis(Tokens.UPDATE);
if (token.tokenType == Tokens.OF) {
readThis(Tokens.OF);
OrderedHashSet colNames = readColumnNameList(null, false);
}
}
}
StatementDMQL cs = new StatementQuery(session, queryExpression, compileContext);
return cs;
}
use of org.hsqldb_voltpatches.lib.OrderedHashSet in project voltdb by VoltDB.
the class ParserDQL method readColumnNames.
OrderedHashSet readColumnNames(BitMap quotedFlags, boolean readAscDesc) {
readThis(Tokens.OPENBRACKET);
OrderedHashSet set = readColumnNameList(quotedFlags, readAscDesc);
readThis(Tokens.CLOSEBRACKET);
return set;
}
Aggregations