"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "hsqldb/src/org/hsqldb/ParserDQL.java" between
hsqldb-2.7.0.zip and hsqldb-2.7.1.zip

About: HSQLDB (HyperSQL DataBase) is a SQL relational database engine written in Java. It supports nearly full ANSI-92 SQL (BNF format) and full core SQL:2008.

ParserDQL.java  (hsqldb-2.7.0):ParserDQL.java  (hsqldb-2.7.1)
skipping to change at line 68 skipping to change at line 68
import org.hsqldb.types.IntervalType; import org.hsqldb.types.IntervalType;
import org.hsqldb.types.NumberType; import org.hsqldb.types.NumberType;
import org.hsqldb.types.Type; import org.hsqldb.types.Type;
import org.hsqldb.types.Types; import org.hsqldb.types.Types;
import org.hsqldb.types.UserTypeModifier; import org.hsqldb.types.UserTypeModifier;
/** /**
* Parser for DQL statements * Parser for DQL statements
* *
* @author Fred Toussi (fredt@users dot sourceforge.net) * @author Fred Toussi (fredt@users dot sourceforge.net)
* @version 2.7.0 * @version 2.7.1
* @since 1.9.0 * @since 1.9.0
*/ */
public class ParserDQL extends ParserBase { public class ParserDQL extends ParserBase {
protected Database database; protected Database database;
protected Session session; protected Session session;
protected final CompileContext compileContext; protected final CompileContext compileContext;
/** /**
* Constructs a new Parser object with the given context. * Constructs a new Parser object with the given context.
skipping to change at line 155 skipping to change at line 155
if (typeNumber == Integer.MIN_VALUE) { if (typeNumber == Integer.MIN_VALUE) {
if (includeUserTypes) { if (includeUserTypes) {
checkIsSchemaObjectName(); checkIsSchemaObjectName();
Type type = database.schemaManager.findDomainOrUDT(session, Type type = database.schemaManager.findDomainOrUDT(session,
token.tokenString, token.namePrefix, token.namePrePrefix, token.tokenString, token.namePrefix, token.namePrePrefix,
token.namePrePrePrefix); token.namePrePrePrefix);
if (type != null) { if (type != null) {
getRecordedToken().setExpression(type); getRecordedToken().setExpression(type);
compileContext.addSchemaObject(type); compileContext.addDomainOrType(type);
read(); read();
return type; return type;
} }
} }
if (token.namePrefix != null) { if (token.namePrefix != null) {
throw Error.error(ErrorCode.X_42509, token.tokenString); throw Error.error(ErrorCode.X_42509, token.tokenString);
} }
skipping to change at line 1063 skipping to change at line 1063
} finally { } finally {
compileContext.unregisterSubqueries(); compileContext.unregisterSubqueries();
} }
} }
void XreadWithClause() { void XreadWithClause() {
if (token.tokenType == Tokens.WITH) { if (token.tokenType == Tokens.WITH) {
read(); read();
compileContext.unregisterSubqueries(); compileContext.unregisterSubqueries();
compileContext.registerSubquery(SqlInvariants.RECURSIVE_TABLE);
boolean recursive = readIfThis(Tokens.RECURSIVE); boolean recursive = readIfThis(Tokens.RECURSIVE);
while (true) { while (true) {
checkIsSimpleName(); checkIsSimpleName();
HsqlName[] nameList = null; HsqlName[] nameList = null;
HsqlName queryName = HsqlName queryName =
database.nameManager.newHsqlName(token.tokenString, database.nameManager.newHsqlName(token.tokenString,
isDelimitedIdentifier(), isDelimitedIdentifier(),
SchemaObject.SUBQUERY); SchemaObject.SUBQUERY);
queryName.schema = SqlInvariants.SYSTEM_SCHEMA_HSQLNAME; queryName.schema = SqlInvariants.SYSTEM_SCHEMA_HSQLNAME;
read(); read();
compileContext.registerSubquery(queryName.name);
if (token.tokenType == Tokens.OPENBRACKET) { if (token.tokenType == Tokens.OPENBRACKET) {
nameList = readColumnNames(queryName); nameList = readColumnNames(queryName);
} else if (recursive) { } else if (recursive) {
throw unexpectedTokenRequire(Tokens.T_OPENBRACKET); throw unexpectedTokenRequire(Tokens.T_OPENBRACKET);
} }
readThis(Tokens.AS); readThis(Tokens.AS);
readThis(Tokens.OPENBRACKET); readThis(Tokens.OPENBRACKET);
TableDerived td; TableDerived td;
td = XreadTableNamedSubqueryBody(queryName, nameList, compileContext.registerSubquery(queryName.name);
recursive
? OpTypes.RECURSIVE_SUBQUERY td = XreadTableNamedSubqueryBody(queryName, nameList);
: OpTypes.TABLE_SUBQUERY);
if (nameList == null) { if (nameList == null) {
boolean[] cols = td.queryExpression.accessibleColumns; boolean[] cols = td.queryExpression.accessibleColumns;
if (ArrayUtil.countTrueElements(cols) < cols.length) { if (ArrayUtil.countTrueElements(cols) < cols.length) {
throw Error.error(ErrorCode.X_42578); throw Error.error(ErrorCode.X_42578);
} }
} }
readThis(Tokens.CLOSEBRACKET); readThis(Tokens.CLOSEBRACKET);
if (td.queryExpression != null if (td.queryExpression != null
&& td.queryExpression.isRecursive()) { && td.queryExpression.isRecursive()) {
XreadRecursiveFeatures(td); XreadRecursiveFeatures(td);
} }
compileContext.registerSubquery(queryName.name, td); compileContext.registerSubquery(queryName.name, td);
compileContext.registerSubquery(SqlInvariants.RECURSIVE_TABLE,
null);
if (token.tokenType == Tokens.COMMA) { if (token.tokenType == Tokens.COMMA) {
read(); read();
continue; continue;
} }
break; break;
} }
} }
skipping to change at line 3208 skipping to change at line 3209
readThis(Tokens.OPENBRACKET); readThis(Tokens.OPENBRACKET);
TableDerived td = TableDerived td =
XreadSubqueryTableBody(OpTypes.TABLE_SUBQUERY); XreadSubqueryTableBody(OpTypes.TABLE_SUBQUERY);
readThis(Tokens.CLOSEBRACKET); readThis(Tokens.CLOSEBRACKET);
return new Expression(OpTypes.TABLE_SUBQUERY, td); return new Expression(OpTypes.TABLE_SUBQUERY, td);
} }
case Tokens.VALUES : { case Tokens.VALUES : {
/*
if (database.sqlSyntaxMys) {
read();
readThis(Tokens.OPENBRACKET);
checkIsSimpleName();
String name = token.tokenString;
if(compileContext.contextuallyTypedExpression) {
e = new ExpressionColumn(name);
} else {
e = new ExpressionValue(null, Type.SQL_INTEGER);
}
read();
readThis(Tokens.CLOSEBRACKET);
return e;
}
*/
throw unexpectedToken(); throw unexpectedToken();
} }
case Tokens.GROUPING : { case Tokens.GROUPING : {
read(); read();
readThis(Tokens.OPENBRACKET); readThis(Tokens.OPENBRACKET);
Expression groupingElements = XreadRowElementList(true); Expression groupingElements = XreadRowElementList(true);
readThis(Tokens.CLOSEBRACKET); readThis(Tokens.CLOSEBRACKET);
skipping to change at line 5477 skipping to change at line 5459
QuerySpecification select = new QuerySpecification(compileContext); QuerySpecification select = new QuerySpecification(compileContext);
Expression e = new ExpressionColumn(OpTypes.MULTICOLUMN); Expression e = new ExpressionColumn(OpTypes.MULTICOLUMN);
select.addSelectColumnExpression(e); select.addSelectColumnExpression(e);
XreadTableReference(select); XreadTableReference(select);
return select; return select;
} }
TableDerived XreadTableNamedSubqueryBody(HsqlName name, TableDerived XreadTableNamedSubqueryBody(HsqlName name,
HsqlName[] columnNames, int type) { HsqlName[] columnNames) {
TableDerived td; TableDerived td;
TableDerived namedtd = null;
int position = getPosition(); int position = getPosition();
int depth = compileContext.getDepth();
switch (type) { if (columnNames == null) {
td = XreadSubqueryTableBody(name, OpTypes.TABLE_SUBQUERY);
case OpTypes.RECURSIVE_SUBQUERY : { if (td.queryExpression != null) {
try { td.queryExpression.resolve(session,
td = XreadRecursiveSubqueryBody(name, columnNames); compileContext.getOuterRanges(),
null);
break;
} catch (HsqlException e) {
rewind(position);
compileContext.decrementDepth(depth);
}
} }
// fall through td.prepareTable(session);
case OpTypes.TABLE_SUBQUERY : { } else {
try { try {
td = XreadSubqueryTableBody(name, type); td = XreadSubqueryTableBody(name, OpTypes.TABLE_SUBQUERY);
if (td.queryExpression != null) {
td.canRecompile = true;
td.queryExpression.resolve( if (td.queryExpression != null) {
session, compileContext.getOuterRanges(), null); td.queryExpression.resolve(session,
} compileContext.getOuterRanges(),
null);
}
td.prepareTable(session, columnNames); td.prepareTable(session, columnNames);
} catch (HsqlException e) {
HsqlException ex = e;
break; if (e.getErrorCode() != ErrorCode.X_42501) {
} catch (HsqlException e) { if (lastError != null
if (database.sqlSyntaxDb2 || database.sqlSyntaxOra) { && lastError.getErrorCode()
rewind(position); == -ErrorCode.X_42501) {
compileContext.decrementDepth(depth); ex = lastError;
}
}
td = XreadRecursiveSubqueryBody(name, columnNames); String token = ex.getToken();
break; if (SqlInvariants.RECURSIVE_TABLE.equals(token)
} || name.name.equals(token)) {
rewind(position);
td = XreadRecursiveSubqueryBody(name, columnNames);
} else {
throw e; throw e;
} }
} }
default :
throw unexpectedToken();
} }
return td; return td;
} }
TableDerived XreadRecursiveSubqueryBody(HsqlName name, TableDerived XreadRecursiveSubqueryBody(HsqlName name,
HsqlName[] columnNames) { HsqlName[] columnNames) {
int position = getPosition(); int position = getPosition();
QueryExpression leftQueryExpression = XreadSimpleTable();
compileContext.incrementDepth();
compileContext.incrementDepth();
QuerySpecification leftQuerySpecification = XreadSimpleTable();
leftQuerySpecification.isBaseMergeable = false; leftQueryExpression.isBaseMergeable = false;
leftQuerySpecification.isMergeable = false; leftQueryExpression.isMergeable = false;
leftQuerySpecification.resolveReferences(session, leftQueryExpression.resolveReferences(session,
compileContext.getOuterRanges()); compileContext.getOuterRanges());
leftQuerySpecification.resolve(session); leftQueryExpression.resolve(session);
HsqlName leftName = HsqlName leftName =
database.nameManager.newHsqlName(SqlInvariants.SYSTEM_SUBQUERY, database.nameManager.newHsqlName(SqlInvariants.SYSTEM_SUBQUERY,
false, SchemaObject.SUBQUERY); false, SchemaObject.SUBQUERY);
TableDerived leftTable = newSubQueryTable(leftName, TableDerived leftTable = new TableDerived(database, leftName,
leftQuerySpecification, OpTypes.TABLE_SUBQUERY); TableBase.SYSTEM_SUBQUERY, columnNames,
leftQueryExpression.getColumnTypes());
compileContext.decrementDepth(); TableDerived workTable = new TableDerived(database, name,
leftTable.prepareTable(session, columnNames); TableBase.SYSTEM_SUBQUERY, columnNames,
leftQueryExpression.getColumnTypes());
TableDerived workTable = newSubQueryTable(name,
leftQuerySpecification, OpTypes.TABLE_SUBQUERY);
workTable.prepareTable(session, columnNames);
workTable.queryExpression = null;
HsqlName recursiveName = HsqlName recursiveName =
database.nameManager.newHsqlName("RECURSIVE_TABLE", false, database.nameManager.newHsqlName(SqlInvariants.RECURSIVE_TABLE,
SchemaObject.SUBQUERY); false, SchemaObject.SUBQUERY);
TableDerived recursiveTable = newSubQueryTable(name, TableDerived recursiveTable = new TableDerived(database,
leftQuerySpecification, OpTypes.TABLE_SUBQUERY); recursiveName, TableBase.SYSTEM_SUBQUERY, columnNames,
leftQueryExpression.getColumnTypes());
recursiveTable.prepareTable(session, columnNames);
recursiveTable.queryExpression = null;
compileContext.registerSubquery(recursiveName.name);
compileContext.registerSubquery(recursiveName.name, recursiveTable); compileContext.registerSubquery(recursiveName.name, recursiveTable);
compileContext.registerSubquery(name.name);
compileContext.registerSubquery(name.name, workTable); compileContext.registerSubquery(name.name, workTable);
checkIsThis(Tokens.UNION); checkIsThis(Tokens.UNION);
int unionType = XreadUnionType(); int unionType = XreadUnionType();
compileContext.incrementDepth();
QuerySpecification rightQuerySpecification = XreadSimpleTable(); QuerySpecification rightQuerySpecification = XreadSimpleTable();
QueryExpression queryExpression = new QueryExpression(compileContext, QueryExpression queryExpression = new QueryExpression(compileContext,
leftQuerySpecification); leftQueryExpression);
rightQuerySpecification.isBaseMergeable = false; rightQuerySpecification.isBaseMergeable = false;
rightQuerySpecification.isMergeable = false; rightQuerySpecification.isMergeable = false;
rightQuerySpecification.resolveReferences(session, rightQuerySpecification.resolveReferences(session,
compileContext.getOuterRanges()); compileContext.getOuterRanges());
queryExpression.addUnion(rightQuerySpecification, unionType); queryExpression.addUnion(rightQuerySpecification, unionType);
queryExpression.isRecursive = true; queryExpression.isRecursive = true;
queryExpression.recursiveWorkTable = workTable; queryExpression.recursiveWorkTable = workTable;
skipping to change at line 5649 skipping to change at line 5618
TableDerived XreadSubqueryTableBody(int type) { TableDerived XreadSubqueryTableBody(int type) {
return XreadSubqueryTableBody(null, type); return XreadSubqueryTableBody(null, type);
} }
TableDerived XreadSubqueryTableBody(HsqlName name, int type) { TableDerived XreadSubqueryTableBody(HsqlName name, int type) {
int position = getPosition(); int position = getPosition();
compileContext.incrementDepth(); compileContext.incrementDepth();
QueryExpression queryExpression = XreadQueryExpression(); try {
TableDerived td = null; QueryExpression queryExpression = XreadQueryExpression();
TableDerived td = null;
if (type == OpTypes.EXISTS) { if (type == OpTypes.EXISTS) {
queryExpression.setAsExists(); queryExpression.setAsExists();
} }
if (queryExpression.isValueList) { if (queryExpression.isValueList) {
td = ((QuerySpecification) queryExpression).getValueListTable(); td = ((QuerySpecification) queryExpression)
} .getValueListTable();
}
if (td == null) { if (td == null) {
td = newSubQueryTable(name, queryExpression, type); td = newSubQueryTable(name, queryExpression, type);
} }
String sql = getLastPart(position); String sql = getLastPart(position);
td.setSQL(sql); td.setSQL(sql);
compileContext.decrementDepth();
return td; return td;
} finally {
compileContext.decrementDepth();
}
} }
TableDerived XreadViewSubqueryTable(View view, boolean resolve) { TableDerived XreadViewSubqueryTable(View view, boolean resolve) {
compileContext.incrementDepth(); compileContext.incrementDepth();
QueryExpression queryExpression; QueryExpression queryExpression;
try { try {
queryExpression = XreadQueryExpression(); queryExpression = XreadQueryExpression();
skipping to change at line 6116 skipping to change at line 6089
read(); read();
if (token.tokenType != Tokens.WHEN) { if (token.tokenType != Tokens.WHEN) {
predicand = XreadRowValuePredicand(); predicand = XreadRowValuePredicand();
} }
return readCaseWhen(predicand); return readCaseWhen(predicand);
} }
/** /**
* Reads part of a CASE .. WHEN expression * Reads part of a CASE ... WHEN expression
*/ */
private Expression readCaseWhen(final Expression l) { private Expression readCaseWhen(final Expression l) {
readThis(Tokens.WHEN); readThis(Tokens.WHEN);
Expression condition = null; Expression condition = null;
if (l == null) { if (l == null) {
condition = XreadBooleanValueExpression(); condition = XreadBooleanValueExpression();
} else { } else {
skipping to change at line 7304 skipping to change at line 7277
SchemaObject.TABLE); SchemaObject.TABLE);
if (reference != null) { if (reference != null) {
table = (Table) database.schemaManager.getSchemaObject( table = (Table) database.schemaManager.getSchemaObject(
reference.getTarget()); reference.getTarget());
lastSynonym = reference.getName(); lastSynonym = reference.getName();
} }
} }
if (table == null) { if (table == null) {
throw Error.error(ErrorCode.X_42501, token.tokenString); HsqlException ex = Error.error(ErrorCode.X_42501,
token.tokenString);
ex.setToken(token.tokenString);
throw ex;
} }
} }
getRecordedToken().setExpression(table); getRecordedToken().setExpression(table);
read(); read();
return table; return table;
} }
/** /**
* Returns a period condition (including a default) for all tables with a * Returns a period condition (including a default) for all tables with a
* system period. Otherwise null; * system period, otherwise null;
*/ */
ExpressionPeriodOp XreadQuerySystemPeriodSpecOrNull(Table table) { ExpressionPeriodOp XreadQuerySystemPeriodSpecOrNull(Table table) {
int position = getPosition(); int position = getPosition();
if (!table.isSystemVersioned()) { if (!table.isSystemVersioned()) {
return null; return null;
} }
if (token.tokenType == Tokens.FOR) { if (token.tokenType == Tokens.FOR) {
skipping to change at line 7741 skipping to change at line 7719
// //
private int subqueryDepth; private int subqueryDepth;
private HsqlArrayList namedSubqueries; private HsqlArrayList namedSubqueries;
// //
private OrderedIntKeyHashMap parameters = new OrderedIntKeyHashMap(); private OrderedIntKeyHashMap parameters = new OrderedIntKeyHashMap();
private HsqlArrayList usedSequences = new HsqlArrayList(16, true); private HsqlArrayList usedSequences = new HsqlArrayList(16, true);
private HsqlArrayList usedRoutines = new HsqlArrayList(16, true); private HsqlArrayList usedRoutines = new HsqlArrayList(16, true);
private OrderedIntKeyHashMap rangeVariables = private OrderedIntKeyHashMap rangeVariables =
new OrderedIntKeyHashMap(); new OrderedIntKeyHashMap();
private HsqlArrayList usedObjects = new HsqlArrayList(16, true); private HsqlArrayList usedTypes = new HsqlArrayList(16, true);
Type currentDomain; Type currentDomain;
boolean contextuallyTypedExpression; boolean contextuallyTypedExpression;
boolean onDuplicateTypedExpression; boolean onDuplicateTypedExpression;
Routine callProcedure; Routine callProcedure;
// //
private RangeGroup[] outerRangeGroups = RangeGroup.emptyArray; private RangeGroup[] outerRangeGroups = RangeGroup.emptyArray;
// //
private final int initialRangeVarIndex; private final int initialRangeVarIndex;
skipping to change at line 7788 skipping to change at line 7766
rangeVarIndex = initialRangeVarIndex; rangeVarIndex = initialRangeVarIndex;
subqueryDepth = 0; subqueryDepth = 0;
rangeVariables.clear(); rangeVariables.clear();
parameters.clear(); parameters.clear();
usedSequences.clear(); usedSequences.clear();
usedRoutines.clear(); usedRoutines.clear();
callProcedure = null; callProcedure = null;
usedObjects.clear(); usedTypes.clear();
outerRangeGroups = RangeGroup.emptyArray; outerRangeGroups = RangeGroup.emptyArray;
// //
currentDomain = null; currentDomain = null;
contextuallyTypedExpression = false; contextuallyTypedExpression = false;
} }
public int getDepth() { public int getDepth() {
return subqueryDepth; return subqueryDepth;
skipping to change at line 8088 skipping to change at line 8066
set.put(name, td); set.put(name, td);
} }
private void unregisterSubqueries() { private void unregisterSubqueries() {
if (namedSubqueries == null) { if (namedSubqueries == null) {
return; return;
} }
for (int i = subqueryDepth; i < namedSubqueries.size(); i++) { for (int i = subqueryDepth; i < namedSubqueries.size(); i++) {
namedSubqueries.set(i, null); OrderedHashMap set = (OrderedHashMap) namedSubqueries.get(i);
if (set != null) {
set.clear();
}
} }
} }
private TableDerived getNamedSubQuery(String name) { private TableDerived getNamedSubQuery(String name) {
if (baseContext != null) { if (baseContext != null) {
TableDerived td = baseContext.getNamedSubQuery(name); TableDerived td = baseContext.getNamedSubQuery(name);
if (td != null) { if (td != null) {
return td; return td;
skipping to change at line 8117 skipping to change at line 8099
if (namedSubqueries.size() <= i) { if (namedSubqueries.size() <= i) {
continue; continue;
} }
OrderedHashMap set = (OrderedHashMap) namedSubqueries.get(i); OrderedHashMap set = (OrderedHashMap) namedSubqueries.get(i);
if (set == null) { if (set == null) {
continue; continue;
} }
TableDerived td = (TableDerived) set.get(name); if (set.getIndex(name) >= 0) {
TableDerived td = (TableDerived) set.get(name);
if (td == null) {
HsqlException ex = Error.error(ErrorCode.X_42501,
name);
ex.setToken(name);
throw ex;
}
if (td != null) {
return td; return td;
} }
} }
return null; return null;
} }
private void addParameter(ExpressionColumn e, int position) { private void addParameter(ExpressionColumn e, int position) {
parameters.put(position, e); parameters.put(position, e);
} }
private void addSchemaObject(SchemaObject object) { private void addDomainOrType(SchemaObject object) {
usedObjects.add(object); usedTypes.add(object);
} }
private void addSequence(SchemaObject object) { private void addSequence(SchemaObject object) {
usedSequences.add(object); usedSequences.add(object);
} }
void addFunctionCall(FunctionSQLInvoked function) { void addFunctionCall(FunctionSQLInvoked function) {
usedRoutines.add(function); usedRoutines.add(function);
} }
skipping to change at line 8172 skipping to change at line 8163
public OrderedHashSet getSchemaObjectNames() { public OrderedHashSet getSchemaObjectNames() {
OrderedHashSet set = new OrderedHashSet(); OrderedHashSet set = new OrderedHashSet();
for (int i = 0; i < usedSequences.size(); i++) { for (int i = 0; i < usedSequences.size(); i++) {
SchemaObject object = (SchemaObject) usedSequences.get(i); SchemaObject object = (SchemaObject) usedSequences.get(i);
set.add(object.getName()); set.add(object.getName());
} }
for (int i = 0; i < usedObjects.size(); i++) { for (int i = 0; i < usedTypes.size(); i++) {
SchemaObject object = (SchemaObject) usedObjects.get(i); SchemaObject object = (SchemaObject) usedTypes.get(i);
set.add(object.getName()); set.add(object.getName());
} }
for (int i = 0; i < rangeVariables.size(); i++) { for (int i = 0; i < rangeVariables.size(); i++) {
RangeVariable range = RangeVariable range =
(RangeVariable) rangeVariables.getValueAt(i); (RangeVariable) rangeVariables.getValueAt(i);
if (range.isViewSubquery) { if (range.isViewSubquery) {
continue; continue;
 End of changes. 47 change blocks. 
122 lines changed or deleted 113 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)