Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
3.3.2
-
None
Description
private static final String INSERT_COSMETICS = """ |
INSERT IGNORE INTO cosmetic(name, category)
|
VALUES(?, (SELECT id FROM cosmetic_category WHERE name = ?))
|
"""; |
|
public boolean insertCosmetics() throws SQLException { |
try (Connection connection = dataSource.getConnection(); |
PreparedStatement statement = connection.prepareStatement(INSERT_COSMETICS)) {
|
|
for (CosmeticCategory category : CosmeticCategory.CATEGORIES) { |
for (Cosmetic<?> cosmetic : cosmetics.getRegistrar().getCosmetics(category)) { |
statement.setString(1, cosmetic.getName()); |
statement.setString(2, category.getName()); |
statement.addBatch();
|
}
|
}
|
|
statement.executeBatch();
|
return true; |
} catch (SQLException e) { |
throw e; |
}
|
}
|
The following code worked perfectly in the past, but after upgrading to a newer version of the connector, the second variable is not cleaned up after running addBatch. So only the first addBatch correctly sets the second value (category.getName), while all other queries are executed without changing the second parameter, probably because it is inside a subquery? I tested the code without any batch and it worked perfectly.
Attachments
Issue Links
- is caused by
-
MDEV-23864 BULK insert wrong values when command contain inner select
- Stalled