提交 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;
import org.h2.expression.ExpressionColumn;
import org.h2.expression.ExpressionVisitor;
import org.h2.expression.Parameter;
import org.h2.expression.Wildcard;
import org.h2.index.Cursor;
import org.h2.index.Index;
import org.h2.index.IndexCondition;
......@@ -723,14 +722,11 @@ public class Select extends Query {
String schemaName = expr.getSchemaName();
String tableAlias = expr.getTableAlias();
if (tableAlias == null) {
int temp = i;
expressions.remove(i);
for (TableFilter filter : filters) {
Wildcard c2 = new Wildcard(filter.getTable().getSchema()
.getName(), filter.getTableAlias());
expressions.add(i++, c2);
i = expandColumnList(filter, i);
}
i = temp - 1;
i--;
} else {
TableFilter filter = null;
for (TableFilter f : filters) {
......@@ -747,9 +743,16 @@ public class Select extends Query {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1,
tableAlias);
}
expressions.remove(i);
i = expandColumnList(filter, i);
i--;
}
}
}
private int expandColumnList(TableFilter filter, int index) {
Table t = filter.getTable();
String alias = filter.getTableAlias();
expressions.remove(i);
Column[] columns = t.getColumns();
for (Column c : columns) {
if (filter.isNaturalJoinColumn(c)) {
......@@ -757,11 +760,9 @@ public class Select extends Query {
}
ExpressionColumn ec = new ExpressionColumn(
session.getDatabase(), null, alias, c.getName());
expressions.add(i++, ec);
}
i--;
}
expressions.add(index++, ec);
}
return index;
}
@Override
......
......@@ -3,6 +3,12 @@
-- Initial Developer: H2 Group
--
--- 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;
> X I
> - -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论