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