From bcb298d9377e9e8abca9242df7025be0693ae364 Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 23 Sep 2021 15:47:21 -0500 Subject: [PATCH] Lets not use sqlite syntax in mysql. --- .../ultimatestacker/database/DataManager.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/database/DataManager.java b/src/main/java/com/songoda/ultimatestacker/database/DataManager.java index 1894f18..10ccb5b 100644 --- a/src/main/java/com/songoda/ultimatestacker/database/DataManager.java +++ b/src/main/java/com/songoda/ultimatestacker/database/DataManager.java @@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.database; import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.database.DataManagerAbstract; import com.songoda.core.database.DatabaseConnector; +import com.songoda.core.database.SQLiteConnector; import com.songoda.ultimatestacker.settings.Settings; import com.songoda.ultimatestacker.stackable.block.BlockStack; import com.songoda.ultimatestacker.stackable.entity.ColdEntityStack; @@ -230,19 +231,21 @@ public class DataManager extends DataManagerAbstract { Map entities = new HashMap<>(); - String selectOldEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities where updated_at <= date('now','-" + Settings.DATABASE_PURGE.getInt() + " day')"; - try (Statement statement = connection.createStatement()) { - List toDelete = new ArrayList<>(); + if (this.databaseConnector instanceof SQLiteConnector) { + String selectOldEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities where updated_at <= date('now','-" + Settings.DATABASE_PURGE.getInt() + " day')"; + try (Statement statement = connection.createStatement()) { + List toDelete = new ArrayList<>(); - ResultSet result = statement.executeQuery(selectOldEntities); - while (result.next()) { - int hostId = result.getInt("id"); - toDelete.add(String.valueOf(hostId)); + ResultSet result = statement.executeQuery(selectOldEntities); + while (result.next()) { + int hostId = result.getInt("id"); + toDelete.add(String.valueOf(hostId)); + } + statement.execute("DELETE FROM " + this.getTablePrefix() + "host_entities where updated_at <= date('now','-" + Settings.DATABASE_PURGE.getInt() + " day')"); + statement.execute("DELETE FROM " + this.getTablePrefix() + "stacked_entities where host IN (" + String.join(", ", toDelete) + ")"); + } catch (Exception e) { + e.printStackTrace(); } - statement.execute("DELETE FROM " + this.getTablePrefix() + "host_entities where updated_at <= date('now','-" + Settings.DATABASE_PURGE.getInt() + " day')"); - statement.execute("DELETE FROM " + this.getTablePrefix() + "stacked_entities where host IN (" + String.join(", ", toDelete) + ")"); - } catch (Exception e) { - e.printStackTrace(); }