提交 ceea9031 authored 作者: Thomas Mueller's avatar Thomas Mueller

Queries that use the same table alias multiple times now work. Before, the…

Queries that use the same table alias multiple times now work. Before, the select expression list was expanded incorrectly. Example: "select * from a as x, b as x".
上级 d06ff11c
...@@ -23,7 +23,6 @@ import org.h2.expression.Expression; ...@@ -23,7 +23,6 @@ import org.h2.expression.Expression;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor; import org.h2.expression.ExpressionVisitor;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.expression.Wildcard;
import org.h2.index.Cursor; import org.h2.index.Cursor;
import org.h2.index.Index; import org.h2.index.Index;
import org.h2.index.IndexCondition; import org.h2.index.IndexCondition;
...@@ -723,14 +722,11 @@ public class Select extends Query { ...@@ -723,14 +722,11 @@ public class Select extends Query {
String schemaName = expr.getSchemaName(); String schemaName = expr.getSchemaName();
String tableAlias = expr.getTableAlias(); String tableAlias = expr.getTableAlias();
if (tableAlias == null) { if (tableAlias == null) {
int temp = i;
expressions.remove(i); expressions.remove(i);
for (TableFilter filter : filters) { for (TableFilter filter : filters) {
Wildcard c2 = new Wildcard(filter.getTable().getSchema() i = expandColumnList(filter, i);
.getName(), filter.getTableAlias());
expressions.add(i++, c2);
} }
i = temp - 1; i--;
} else { } else {
TableFilter filter = null; TableFilter filter = null;
for (TableFilter f : filters) { for (TableFilter f : filters) {
...@@ -747,9 +743,16 @@ public class Select extends Query { ...@@ -747,9 +743,16 @@ public class Select extends Query {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1,
tableAlias); tableAlias);
} }
expressions.remove(i);
i = expandColumnList(filter, i);
i--;
}
}
}
private int expandColumnList(TableFilter filter, int index) {
Table t = filter.getTable(); Table t = filter.getTable();
String alias = filter.getTableAlias(); String alias = filter.getTableAlias();
expressions.remove(i);
Column[] columns = t.getColumns(); Column[] columns = t.getColumns();
for (Column c : columns) { for (Column c : columns) {
if (filter.isNaturalJoinColumn(c)) { if (filter.isNaturalJoinColumn(c)) {
...@@ -757,11 +760,9 @@ public class Select extends Query { ...@@ -757,11 +760,9 @@ public class Select extends Query {
} }
ExpressionColumn ec = new ExpressionColumn( ExpressionColumn ec = new ExpressionColumn(
session.getDatabase(), null, alias, c.getName()); session.getDatabase(), null, alias, c.getName());
expressions.add(i++, ec); expressions.add(index++, ec);
}
i--;
}
} }
return index;
} }
@Override @Override
......
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
-- Initial Developer: H2 Group -- Initial Developer: H2 Group
-- --
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
select * from table(a int=(1)), table(b int=(2));
> A B
> - -
> 1 2
> rows: 1
select x, x in(2, 3) i from system_range(1, 2) group by x; select x, x in(2, 3) i from system_range(1, 2) group by x;
> X I > X I
> - ----- > - -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论