提交 86f65e5d authored 作者: Thomas Mueller's avatar Thomas Mueller

Nested subqueries didn't work for INSERT INTO and IN(..).

上级 16ceecac
......@@ -862,6 +862,18 @@ public class Parser {
return prep;
}
private boolean isSelect() throws SQLException {
int start = lastParseIndex;
while (readIf("(")) {
// need to read ahead, it could be a nested union:
// ((select 1) union (select 1))
}
boolean select = isToken("SELECT") || isToken("FROM");
parseIndex = start;
read();
return select;
}
private Merge parseMerge() throws SQLException {
Merge command = new Merge(session);
currentPrepared = command;
......@@ -869,7 +881,7 @@ public class Parser {
Table table = readTableOrView();
command.setTable(table);
if (readIf("(")) {
if (isToken("SELECT") || isToken("FROM")) {
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
return command;
......@@ -913,7 +925,7 @@ public class Parser {
command.setSortedInsertMode(true);
}
if (readIf("(")) {
if (isToken("SELECT") || isToken("FROM")) {
if (isSelect()) {
command.setQuery(parseSelect());
read(")");
return command;
......@@ -950,19 +962,8 @@ public class Parser {
Table table;
String alias = null;
if (readIf("(")) {
// need to read ahead, it could be a nested union or join:
// select 1 from (((select 1) union (select 1)) union (select 1));
// select * from ((test d1 inner join test d2 on d1.id = d2.id)
// inner join test d3 on d1.id = d3.id) inner join test d4
// on d4.id = d1.id;
if (isSelect()) {
int start = lastParseIndex;
while (readIf("(")) {
// ignore, but go back later
}
if (isToken("SELECT") || isToken("FROM")) {
parseIndex = start;
read();
start = lastParseIndex;
int paramIndex = parameters.size();
Query query = parseSelectUnion();
read(")");
......@@ -982,8 +983,6 @@ public class Parser {
alias = session.getNextSystemIdentifier(sqlCommand);
table = TableView.createTempView(s, session.getUser(), alias, query, currentSelect);
} else {
parseIndex = start;
read();
TableFilter top = readTableFilter(fromOuter);
top = readJoin(top, currentSelect, fromOuter);
read(")");
......@@ -1755,7 +1754,7 @@ public class Parser {
if (readIf(")")) {
r = ValueExpression.get(ValueBoolean.get(false));
} else {
if (isToken("SELECT") || isToken("FROM")) {
if (isSelect()) {
Query query = parseSelect();
r = new ConditionInSelect(database, r, query, false, Comparison.EQUAL);
} else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论