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

Parse WHEN MATCHED THEN and WHEN NOT MATCHED THEN in any order

上级 e51f3f01
...@@ -1168,32 +1168,9 @@ public class Parser { ...@@ -1168,32 +1168,9 @@ public class Parser {
command.setOnCondition(condition); command.setOnCondition(condition);
read(")"); read(")");
if (readIfAll("WHEN", "MATCHED", "THEN")) { boolean matched = parseWhenMatched(command);
int startMatched = lastParseIndex; if (parseWhenNotMatched(command) && !matched) {
if (readIf("UPDATE")) { parseWhenMatched(command);
Update updateCommand = new Update(session);
//currentPrepared = updateCommand;
TableFilter filter = command.getTargetTableFilter();
updateCommand.setTableFilter(filter);
parseUpdateSetClause(updateCommand, filter, startMatched);
command.setUpdateCommand(updateCommand);
}
startMatched = lastParseIndex;
if (readIf("DELETE")) {
Delete deleteCommand = new Delete(session);
TableFilter filter = command.getTargetTableFilter();
deleteCommand.setTableFilter(filter);
parseDeleteGivenTable(deleteCommand, null, startMatched);
command.setDeleteCommand(deleteCommand);
}
}
if (readIfAll("WHEN", "NOT", "MATCHED", "THEN")) {
if (readIf("INSERT")) {
Insert insertCommand = new Insert(session);
insertCommand.setTable(command.getTargetTable());
parseInsertGivenTable(insertCommand, command.getTargetTable());
command.setInsertCommand(insertCommand);
}
} }
setSQL(command, "MERGE", start); setSQL(command, "MERGE", start);
...@@ -1211,6 +1188,42 @@ public class Parser { ...@@ -1211,6 +1188,42 @@ public class Parser {
return command; return command;
} }
private boolean parseWhenMatched(MergeUsing command) {
if (!readIfAll("WHEN", "MATCHED", "THEN")) {
return false;
}
int startMatched = lastParseIndex;
if (readIf("UPDATE")) {
Update updateCommand = new Update(session);
TableFilter filter = command.getTargetTableFilter();
updateCommand.setTableFilter(filter);
parseUpdateSetClause(updateCommand, filter, startMatched);
command.setUpdateCommand(updateCommand);
}
startMatched = lastParseIndex;
if (readIf("DELETE")) {
Delete deleteCommand = new Delete(session);
TableFilter filter = command.getTargetTableFilter();
deleteCommand.setTableFilter(filter);
parseDeleteGivenTable(deleteCommand, null, startMatched);
command.setDeleteCommand(deleteCommand);
}
return true;
}
private boolean parseWhenNotMatched(MergeUsing command) {
if (!readIfAll("WHEN", "NOT", "MATCHED", "THEN")) {
return false;
}
if (readIf("INSERT")) {
Insert insertCommand = new Insert(session);
insertCommand.setTable(command.getTargetTable());
parseInsertGivenTable(insertCommand, command.getTargetTable());
command.setInsertCommand(insertCommand);
}
return true;
}
private static void appendTableWithSchemaAndAlias(StringBuilder buff, Table table, String alias) { private static void appendTableWithSchemaAndAlias(StringBuilder buff, Table table, String alias) {
if (table instanceof RangeTable) { if (table instanceof RangeTable) {
buff.append(table.getSQL()); buff.append(table.getSQL());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论