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

Forbid empty WHEN [NOT] MATCHED THEN

上级 40f3269b
...@@ -1207,12 +1207,14 @@ public class Parser { ...@@ -1207,12 +1207,14 @@ public class Parser {
private void parseWhenMatched(MergeUsing command) { private void parseWhenMatched(MergeUsing command) {
read("THEN"); read("THEN");
int startMatched = lastParseIndex; int startMatched = lastParseIndex;
boolean ok = false;
if (readIf("UPDATE")) { if (readIf("UPDATE")) {
Update updateCommand = new Update(session); Update updateCommand = new Update(session);
TableFilter filter = command.getTargetTableFilter(); TableFilter filter = command.getTargetTableFilter();
updateCommand.setTableFilter(filter); updateCommand.setTableFilter(filter);
parseUpdateSetClause(updateCommand, filter, startMatched); parseUpdateSetClause(updateCommand, filter, startMatched);
command.setUpdateCommand(updateCommand); command.setUpdateCommand(updateCommand);
ok = true;
} }
startMatched = lastParseIndex; startMatched = lastParseIndex;
if (readIf("DELETE")) { if (readIf("DELETE")) {
...@@ -1221,6 +1223,10 @@ public class Parser { ...@@ -1221,6 +1223,10 @@ public class Parser {
deleteCommand.setTableFilter(filter); deleteCommand.setTableFilter(filter);
parseDeleteGivenTable(deleteCommand, null, startMatched); parseDeleteGivenTable(deleteCommand, null, startMatched);
command.setDeleteCommand(deleteCommand); command.setDeleteCommand(deleteCommand);
ok = true;
}
if (!ok) {
throw getSyntaxError();
} }
} }
...@@ -1233,6 +1239,8 @@ public class Parser { ...@@ -1233,6 +1239,8 @@ public class Parser {
insertCommand.setTable(command.getTargetTable()); insertCommand.setTable(command.getTargetTable());
parseInsertGivenTable(insertCommand, command.getTargetTable()); parseInsertGivenTable(insertCommand, command.getTargetTable());
command.setInsertCommand(insertCommand); command.setInsertCommand(insertCommand);
} else {
throw getSyntaxError();
} }
} }
......
...@@ -158,10 +158,20 @@ MERGE INTO TEST USING DUAL ON (ID = 1) ...@@ -158,10 +158,20 @@ MERGE INTO TEST USING DUAL ON (ID = 1)
WHEN; WHEN;
> exception SYNTAX_ERROR_2 > exception SYNTAX_ERROR_2
MERGE INTO TEST USING DUAL ON (ID = 1)
WHEN MATCHED THEN UPDATE SET VALUE = 1
WHEN NOT MATCHED THEN;
> exception SYNTAX_ERROR_2
MERGE INTO TEST USING DUAL ON (ID = 1) MERGE INTO TEST USING DUAL ON (ID = 1)
WHEN NOT MATCHED THEN INSERT (ID, VALUE) VALUES (1, 1) WHEN NOT MATCHED THEN INSERT (ID, VALUE) VALUES (1, 1)
WHEN; WHEN;
> exception SYNTAX_ERROR_2 > exception SYNTAX_ERROR_2
MERGE INTO TEST USING DUAL ON (ID = 1)
WHEN NOT MATCHED THEN INSERT (ID, VALUE) VALUES (1, 1)
WHEN MATCHED THEN;
> exception SYNTAX_ERROR_2
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论