Skip to content

Commit 0861852

Browse files
committed
Fix sql
1 parent f7bf2a8 commit 0861852

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/main/java/org/maxgamer/quickshop/database/DatabaseHelper.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,42 @@ public void updateOwner2UUID(@NotNull String ownerUUID, int x, int y, int z, @No
324324

325325
public void updateExternalInventoryProfileCache(@NotNull Shop shop, int space, int stock) {
326326

327+
if(manager.getDatabase() instanceof MySQLCore){
328+
String sqlString = "INSERT INTO "+plugin.getDbPrefix()+"external_cache (x,y,z,world,space,stock) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE space = ?, stock = ?";
329+
manager.addDelayTask(
330+
new DatabaseTask(sqlString, ps -> {
331+
ps.setInt(1, shop.getLocation().getBlockX());
332+
ps.setInt(2, shop.getLocation().getBlockY());
333+
ps.setInt(3, shop.getLocation().getBlockZ());
334+
ps.setString(4, shop.getLocation().getWorld().getName());
335+
ps.setInt(5, space);
336+
ps.setInt(6, stock);
337+
ps.setInt(7, space);
338+
ps.setInt(8, stock);
339+
}));
340+
}else{
341+
String createString = "INSERT OR IGNORE INTO "+plugin.getDbPrefix()+"external_cache (x,y,z,world,space,stock) VALUES (?,?,?,?,?,?)";
342+
manager.addDelayTask(
343+
new DatabaseTask(createString, ps -> {
344+
ps.setInt(1, shop.getLocation().getBlockX());
345+
ps.setInt(2, shop.getLocation().getBlockY());
346+
ps.setInt(3, shop.getLocation().getBlockZ());
347+
ps.setString(4, shop.getLocation().getWorld().getName());
348+
ps.setInt(5, space);
349+
ps.setInt(6, stock);;
350+
}));
351+
String updateString = "UPDATE "+plugin.getDbPrefix()+"external_cache SET space = ?, stock = ? WHERE x = ? AND y = ? AND z = ? AND world =?";
352+
manager.addDelayTask(
353+
new DatabaseTask(updateString, ps -> {
354+
ps.setInt(1, space);
355+
ps.setInt(2, stock);
356+
ps.setInt(3, shop.getLocation().getBlockX());
357+
ps.setInt(4, shop.getLocation().getBlockY());
358+
ps.setInt(5, shop.getLocation().getBlockZ());
359+
ps.setString(6, shop.getLocation().getWorld().getName());;
360+
}));
361+
}
362+
327363
}
328364

329365
public void updateShop(@NotNull String owner, @NotNull ItemStack item, int unlimited, int shopType,

0 commit comments

Comments
 (0)