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