Skip to content

Commit

Permalink
fix: Compat issues with Postgres queries, close #383
Browse files Browse the repository at this point in the history
(cherry picked from commit 59ed77c)
  • Loading branch information
WiIIiam278 committed Sep 29, 2024
1 parent 46e0879 commit 6cc2a0d
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,16 @@ protected void rotateSnapshots(@NotNull User user) {
if (unpinnedUserData.size() > maxSnapshots) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
DELETE FROM %user_data_table%
WHERE player_uuid=?
AND pinned=FALSE
ORDER BY timestamp ASC
LIMIT %entry_count%;""".replace("%entry_count%",
WITH cte AS (
SELECT id
FROM user_data_table
WHERE player_uuid=?
AND pinned=FALSE
ORDER BY timestamp ASC
LIMIT %entry_count%
)
DELETE FROM user_data_table
WHERE id IN (SELECT id FROM cte);""".replace("%entry_count%",
Integer.toString(unpinnedUserData.size() - maxSnapshots))))) {
statement.setObject(1, user.getUuid());
statement.executeUpdate();
Expand All @@ -349,10 +354,9 @@ public boolean deleteSnapshot(@NotNull User user, @NotNull UUID versionUuid) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
DELETE FROM %user_data_table%
WHERE player_uuid=? AND version_uuid=?
LIMIT 1;"""))) {
WHERE player_uuid=? AND version_uuid=?;"""))) {
statement.setObject(1, user.getUuid());
statement.setString(2, versionUuid.toString());
statement.setObject(2, versionUuid);
return statement.executeUpdate() > 0;
}
} catch (SQLException e) {
Expand Down

0 comments on commit 6cc2a0d

Please sign in to comment.