Fixed order by related exception with some mysql versions

This commit is contained in:
Risto Lahtela 2021-03-21 11:09:39 +02:00
parent 0dd5d41955
commit 624ed50054
2 changed files with 28 additions and 3 deletions

View File

@ -206,7 +206,7 @@ public class UserInfoQueries {
FROM + UserInfoTable.TABLE_NAME +
") q1" +
GROUP_BY + "address" +
ORDER_BY + "address DESC";
ORDER_BY + "address ASC";
return new QueryStatement<Map<String, Integer>>(sql, 100) {
@Override
@ -232,7 +232,7 @@ public class UserInfoQueries {
FROM + UserInfoTable.TABLE_NAME +
WHERE + UserInfoTable.SERVER_UUID + "=?" +
GROUP_BY + "address" +
ORDER_BY + "address DESC";
ORDER_BY + "address ASC";
return new QueryStatement<Map<String, Integer>>(sql, 100) {
@Override
@ -255,7 +255,7 @@ public class UserInfoQueries {
public static Query<List<String>> uniqueJoinAddresses() {
String sql = SELECT + DISTINCT + "LOWER(COALESCE(" + UserInfoTable.JOIN_ADDRESS + ", ?)) as address" +
FROM + UserInfoTable.TABLE_NAME +
ORDER_BY + UserInfoTable.JOIN_ADDRESS + " DESC";
ORDER_BY + "address ASC";
return new QueryStatement<List<String>>(sql, 100) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {

View File

@ -310,6 +310,31 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
assertEquals(expected, result);
}
@Test
default void joinAddressFilterOptionsAreFetched() {
joinAddressIsUpdatedUponSecondLogin();
List<String> expected = Collections.singletonList(TestConstants.GET_PLAYER_HOSTNAME.get().toLowerCase());
List<String> result = db().query(UserInfoQueries.uniqueJoinAddresses());
assertEquals(expected, result);
}
@Test
default void joinAddressFilterOptionsAreFetchedWhenThereAreMultiple() {
joinAddressIsUpdatedUponSecondLogin();
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> TestConstants.GET_PLAYER_HOSTNAME.get() + "_b"));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> TestConstants.GET_PLAYER_HOSTNAME.get() + "_a"));
List<String> expected = Arrays.asList(
TestConstants.GET_PLAYER_HOSTNAME.get().toLowerCase() + "_a",
TestConstants.GET_PLAYER_HOSTNAME.get().toLowerCase() + "_b"
);
List<String> result = db().query(UserInfoQueries.uniqueJoinAddresses());
assertEquals(expected, result);
}
@Test
default void joinAddressFilterUUIDsAreFetched() {
joinAddressIsUpdatedUponSecondLogin();