Hello Diego,
Just to clarify, in 3.5.1, returnMultiValuesGeneratedIds is no longer applied to batch insertion with ON DUPLICATE KEY UPDATE.
Is it intentional?
Basically, the following test passes with 3.5.0, but fails with 3.5.1.
// NOTE: returnMultiValuesGeneratedIds is enabled
|
try (Statement stmt = con.createStatement()) {
|
stmt.execute("drop table if exists test");
|
stmt.execute("create table test (id int auto_increment primary key, name varchar(16))");
|
stmt.execute("insert into test (id, name) values (1,'name1'), (2, 'name2'), (3, 'three')");
|
con.commit();
|
}
|
try (PreparedStatement stmt = con.prepareStatement(
|
"insert into test (id, name) values (?,?) on duplicate key update name = values(name)",
|
Statement.RETURN_GENERATED_KEYS)) {
|
stmt.setInt(1, 1);
|
stmt.setString(2, "one");
|
stmt.addBatch();
|
|
stmt.setNull(1, Types.INTEGER);
|
stmt.setString(2, "foo");
|
stmt.addBatch();
|
|
int[] batchResult = stmt.executeBatch();
|
assertEquals(2, batchResult.length);
|
assertEquals(2, batchResult[0]);
|
assertEquals(1, batchResult[1]);
|
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
assertTrue(rs.next());
|
assertEquals(1, rs.getInt(1));
|
assertTrue(rs.next());
|
assertEquals(4, rs.getInt(1));
|
assertFalse(rs.next());
|
}
|
}
|
Hello Diego,
Just to clarify, in 3.5.1, returnMultiValuesGeneratedIds is no longer applied to batch insertion with ON DUPLICATE KEY UPDATE.
Is it intentional?
Basically, the following test passes with 3.5.0, but fails with 3.5.1.
// NOTE: returnMultiValuesGeneratedIds is enabled
con.commit();
}
Statement.RETURN_GENERATED_KEYS)) {
stmt.addBatch();
stmt.addBatch();
assertTrue(rs.next());
assertTrue(rs.next());
assertFalse(rs.next());
}
}