提交 5a456a39 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse qualified names of columns in ON DUPLICATE KEY UPDATE

上级 3b88858e
......@@ -1232,7 +1232,24 @@ public class Parser {
read("KEY");
read("UPDATE");
do {
Column column = parseColumn(table);
String columnName = readColumnIdentifier();
if (readIf(".")) {
String schemaOrTableName = columnName;
String tableOrColumnName = readColumnIdentifier();
if (readIf(".")) {
if (!table.getSchema().getName().equals(schemaOrTableName)) {
throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH);
}
columnName = readColumnIdentifier();
} else {
columnName = tableOrColumnName;
tableOrColumnName = schemaOrTableName;
}
if (!table.getName().equals(tableOrColumnName)) {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableOrColumnName);
}
}
Column column = table.getColumn(columnName);
read("=");
Expression expression;
if (readIf("DEFAULT")) {
......
......@@ -77,6 +77,17 @@ public class TestCompatibility extends TestBase {
assertEquals(2, rs.getInt(1));
assertEquals("c", rs.getString(2));
assertFalse(rs.next());
// Check qualified names in ON UPDATE case
assertEquals(2, stat.executeUpdate("insert into s2.test(id, name) values(2, 'd') " +
"on duplicate key update test.name = values(name)"));
assertThrows(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, stat)
.executeUpdate("insert into s2.test(id, name) values(2, 'd') " +
"on duplicate key update test2.name = values(name)");
assertEquals(2, stat.executeUpdate("insert into s2.test(id, name) values(2, 'e') " +
"on duplicate key update s2.test.name = values(name)"));
assertThrows(ErrorCode.SCHEMA_NAME_MUST_MATCH, stat)
.executeUpdate("insert into s2.test(id, name) values(2, 'd') " +
"on duplicate key update s3.test.name = values(name)");
stat.execute("drop schema s2 cascade");
c.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论