mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Fix player insert duplicate key issue with PSQL (#3223)
This commit is contained in:
parent
10f698b70f
commit
d6c810aa71
@ -94,7 +94,10 @@ public class SqlStorage implements StorageImplementation {
|
|||||||
private static final String PLAYER_SELECT_UUID_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? LIMIT 1";
|
private static final String PLAYER_SELECT_UUID_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? LIMIT 1";
|
||||||
private static final String PLAYER_SELECT_USERNAME_BY_UUID = "SELECT username FROM '{prefix}players' WHERE uuid=? LIMIT 1";
|
private static final String PLAYER_SELECT_USERNAME_BY_UUID = "SELECT username FROM '{prefix}players' WHERE uuid=? LIMIT 1";
|
||||||
private static final String PLAYER_UPDATE_USERNAME_FOR_UUID = "UPDATE '{prefix}players' SET username=? WHERE uuid=?";
|
private static final String PLAYER_UPDATE_USERNAME_FOR_UUID = "UPDATE '{prefix}players' SET username=? WHERE uuid=?";
|
||||||
private static final String PLAYER_INSERT = "INSERT INTO '{prefix}players' (uuid, username, primary_group) VALUES(?, ?, ?)";
|
private static final Map<String, String> PLAYER_INSERT = ImmutableMap.of(
|
||||||
|
"PostgreSQL", "INSERT INTO '{prefix}players' (uuid, username, primary_group) VALUES(?, ?, ?) ON CONFLICT DO UPDATE SET username=?, primary_group=?"
|
||||||
|
);
|
||||||
|
private static final String PLAYER_INSERT_DEFAULT = "INSERT INTO '{prefix}players' (uuid, username, primary_group) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE username=?, primary_group=?";
|
||||||
private static final String PLAYER_DELETE = "DELETE FROM '{prefix}players' WHERE uuid=?";
|
private static final String PLAYER_DELETE = "DELETE FROM '{prefix}players' WHERE uuid=?";
|
||||||
private static final String PLAYER_SELECT_ALL_UUIDS_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
private static final String PLAYER_SELECT_ALL_UUIDS_BY_USERNAME = "SELECT uuid FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
||||||
private static final String PLAYER_DELETE_ALL_UUIDS_BY_USERNAME = "DELETE FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
private static final String PLAYER_DELETE_ALL_UUIDS_BY_USERNAME = "DELETE FROM '{prefix}players' WHERE username=? AND NOT uuid=?";
|
||||||
@ -621,10 +624,12 @@ public class SqlStorage implements StorageImplementation {
|
|||||||
ps.execute();
|
ps.execute();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) {
|
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT.getOrDefault(this.connectionFactory.getImplementationName(), PLAYER_INSERT_DEFAULT)))) {
|
||||||
ps.setString(1, uniqueId.toString());
|
ps.setString(1, uniqueId.toString());
|
||||||
ps.setString(2, username);
|
ps.setString(2, username);
|
||||||
ps.setString(3, GroupManager.DEFAULT_GROUP_NAME);
|
ps.setString(3, GroupManager.DEFAULT_GROUP_NAME);
|
||||||
|
ps.setString(4, username);
|
||||||
|
ps.setString(5, GroupManager.DEFAULT_GROUP_NAME);
|
||||||
ps.execute();
|
ps.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -897,10 +902,12 @@ public class SqlStorage implements StorageImplementation {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// insert
|
// insert
|
||||||
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT))) {
|
try (PreparedStatement ps = c.prepareStatement(this.statementProcessor.apply(PLAYER_INSERT.getOrDefault(this.connectionFactory.getImplementationName(), PLAYER_INSERT_DEFAULT)))) {
|
||||||
ps.setString(1, user.toString());
|
ps.setString(1, user.toString());
|
||||||
ps.setString(2, data.username);
|
ps.setString(2, data.username);
|
||||||
ps.setString(3, data.primaryGroup);
|
ps.setString(3, data.primaryGroup);
|
||||||
|
ps.setString(4, data.username);
|
||||||
|
ps.setString(5, data.primaryGroup);
|
||||||
ps.execute();
|
ps.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user