提交 399ba6a5 authored 作者: Thomas Mueller's avatar Thomas Mueller

The MySQL compatibility feature "insert ... on duplicate key update" did not…

The MySQL compatibility feature "insert ... on duplicate key update" did not work with a non-default schema.
上级 7d64ec33
......@@ -325,7 +325,7 @@ public class Insert extends Prepared implements ResultTarget {
ArrayList<String> variableNames = new ArrayList<String>(
duplicateKeyAssignmentMap.size());
for (int i = 0; i < columns.length; i++) {
String key = session.getCurrentSchemaName() + "." +
String key = table.getSchema().getName() + "." +
table.getName() + "." + columns[i].getName();
variableNames.add(key);
session.setVariable(key,
......@@ -386,7 +386,7 @@ public class Insert extends Prepared implements ResultTarget {
Expression condition = null;
for (Column column : foundIndex.getColumns()) {
ExpressionColumn expr = new ExpressionColumn(session.getDatabase(),
session.getCurrentSchemaName(), table.getName(), column.getName());
table.getSchema().getName(), table.getName(), column.getName());
for (int i = 0; i < columns.length; i++) {
if (expr.getColumnName().equals(columns[i].getName())) {
if (condition == null) {
......
......@@ -36,6 +36,7 @@ public class TestCompatibility extends TestBase {
public void test() throws SQLException {
deleteDb("compatibility");
testOnDuplicateKey();
testCaseSensitiveIdentifiers();
testKeyAsColumnInMySQLMode();
......@@ -54,7 +55,19 @@ public class TestCompatibility extends TestBase {
conn.close();
deleteDb("compatibility");
}
private void testOnDuplicateKey() throws SQLException {
Connection c = getConnection("compatibility;MODE=MYSQL");
Statement stat = c.createStatement();
stat.execute("set mode mysql");
stat.execute("create schema s2");
stat.execute("create table s2.test(id int primary key, name varchar(255))");
stat.execute("insert into s2.test(id, name) values(1, 'a')");
stat.execute("insert into s2.test(id, name) values(1, 'b') on duplicate key update name = values(name)");
stat.execute("drop schema s2");
c.close();
}
private void testKeyAsColumnInMySQLMode() throws SQLException {
Connection c = getConnection("compatibility;MODE=MYSQL");
Statement stat = c.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论