提交 f5c3bd9d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Clear CTEs of previous commands in list for safety

上级 e7211e7e
...@@ -185,4 +185,8 @@ public class CommandContainer extends Command { ...@@ -185,4 +185,8 @@ public class CommandContainer extends Command {
return prepared.getType(); return prepared.getType();
} }
void clearCTE() {
clearCTE(session, prepared);
}
} }
...@@ -17,10 +17,10 @@ import org.h2.result.ResultInterface; ...@@ -17,10 +17,10 @@ import org.h2.result.ResultInterface;
*/ */
class CommandList extends Command { class CommandList extends Command {
private final ArrayList<Command> commands; private final ArrayList<CommandContainer> commands;
private final ArrayList<Parameter> parameters; private final ArrayList<Parameter> parameters;
CommandList(Session session, String sql, ArrayList<Command> commands, ArrayList<Parameter> parameters) { CommandList(Session session, String sql, ArrayList<CommandContainer> commands, ArrayList<Parameter> parameters) {
super(session, sql); super(session, sql);
this.commands = commands; this.commands = commands;
this.parameters = parameters; this.parameters = parameters;
...@@ -33,7 +33,7 @@ class CommandList extends Command { ...@@ -33,7 +33,7 @@ class CommandList extends Command {
private void executeRemaining() { private void executeRemaining() {
for (int i = 1, l = commands.size(); i < l; i++) { for (int i = 1, l = commands.size(); i < l; i++) {
Command command = commands.get(i); CommandContainer command = commands.get(i);
if (command.isQuery()) { if (command.isQuery()) {
command.query(0); command.query(0);
} else { } else {
......
...@@ -673,11 +673,11 @@ public class Parser { ...@@ -673,11 +673,11 @@ public class Parser {
*/ */
public Command prepareCommand(String sql) { public Command prepareCommand(String sql) {
try { try {
Command c = prepareSingleCommand(sql); CommandContainer c = prepareSingleCommand(sql);
if (currentTokenType == SEMICOLON) { if (currentTokenType == SEMICOLON) {
String remaining = originalSQL.substring(parseIndex); String remaining = originalSQL.substring(parseIndex);
if (!StringUtils.isWhitespaceOrEmpty(remaining)) { if (!StringUtils.isWhitespaceOrEmpty(remaining)) {
c = prepareCommandList(c, sql, remaining); return prepareCommandList(c, sql, remaining);
} }
} }
return c; return c;
...@@ -686,19 +686,27 @@ public class Parser { ...@@ -686,19 +686,27 @@ public class Parser {
} }
} }
private Command prepareCommandList(Command c, String sql, String remaining) { private CommandList prepareCommandList(CommandContainer c, String sql, String remaining) {
ArrayList<Command> list = Utils.newSmallArrayList(); ArrayList<CommandContainer> list = Utils.newSmallArrayList();
list.add(c); list.add(c);
do { do {
suppliedParameters = parameters; suppliedParameters = parameters;
suppliedParameterList = indexedParameterList; suppliedParameterList = indexedParameterList;
list.add(prepareSingleCommand(remaining)); try {
c = prepareSingleCommand(remaining);
} catch (Throwable t) {
for (CommandContainer cc : list) {
cc.clearCTE();
}
throw t;
}
list.add(c);
} while (currentTokenType == SEMICOLON } while (currentTokenType == SEMICOLON
&& !StringUtils.isWhitespaceOrEmpty(remaining = originalSQL.substring(parseIndex))); && !StringUtils.isWhitespaceOrEmpty(remaining = originalSQL.substring(parseIndex)));
return new CommandList(session, sql, list, parameters); return new CommandList(session, sql, list, parameters);
} }
private Command prepareSingleCommand(String sql) { private CommandContainer prepareSingleCommand(String sql) {
Prepared p = parse(sql); Prepared p = parse(sql);
if (currentTokenType != SEMICOLON && currentTokenType != END) { if (currentTokenType != SEMICOLON && currentTokenType != END) {
addExpected(SEMICOLON); addExpected(SEMICOLON);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论