Duplicate key logic makes sense here.

This commit is contained in:
2024-03-17 10:42:36 -04:00
parent e06657e53f
commit aa0afa533d
2 changed files with 4 additions and 3 deletions
@@ -87,10 +87,11 @@ public class dbWarehouseHandler extends dbHandlerBase {
JSONObject warehouseJSON = new JSONObject(warehouse.resources);
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_warehouse` SET `warehouse` = ? WHERE `cityUID` = ?")) {
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse` (`cityUUID`, `warehouse`) VALUES (?, ?) " +
"ON DUPLICATE KEY UPDATE `warehouse` = VALUES(`warehouse`)")) {
preparedStatement.setString(2, warehouseJSON.toString());
preparedStatement.setInt(1, warehouse.city.getObjectUUID());
preparedStatement.setString(2, warehouseJSON.toString());
return (preparedStatement.executeUpdate() > 0);