diff --git a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/database/DBOpException.java b/Plan/common/src/main/java/com/djrapitops/plan/exceptions/database/DBOpException.java index e2f5be388..ba6c53e44 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/database/DBOpException.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/exceptions/database/DBOpException.java @@ -142,6 +142,10 @@ public class DBOpException extends IllegalStateException implements ExceptionWit context.related(CONSTRAINT_VIOLATION) .whatToDo("Report this error. NOT NULL constraint violation occurred."); break; + case 1071: + context.related("column byte length exceeded") + .whatToDo("Update your MySQL, column key size was exceeded (max key length is 767 bytes in 5.6) - MySQL 5.7 increases the limit."); + break; default: context.related("Unknown SQL Error code"); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java index 9fb970001..19c3f4eae 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/DataStoreQueries.java @@ -196,7 +196,7 @@ public class DataStoreQueries { statement.setLong(2, registered); statement.setString(3, serverUUID.toString()); statement.setBoolean(4, false); // Banned - statement.setString(5, joinAddress); + statement.setString(5, StringUtils.truncate(joinAddress, JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)); statement.setBoolean(6, false); // Operator } }; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java index 0ec07a7f7..280877c57 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/JoinAddressTable.java @@ -27,6 +27,8 @@ public class JoinAddressTable { public static final String TABLE_NAME = "plan_join_address"; public static final String ID = "id"; public static final String JOIN_ADDRESS = "join_address"; + public static final int JOIN_ADDRESS_MAX_LENGTH = 250; + public static final String SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=LOWER(?))"; public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" + JOIN_ADDRESS + ") VALUES (LOWER(?))"; @@ -37,7 +39,7 @@ public class JoinAddressTable { public static String createTableSQL(DBType dbType) { return CreateTableBuilder.create(TABLE_NAME, dbType) .column(ID, Sql.INT).primaryKey() - .column(JOIN_ADDRESS, Sql.varchar(255)).unique() + .column(JOIN_ADDRESS, Sql.varchar(JOIN_ADDRESS_MAX_LENGTH)).unique() .toString(); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/UserInfoTable.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/UserInfoTable.java index debc96aea..61650d586 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/UserInfoTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/sql/tables/UserInfoTable.java @@ -66,7 +66,7 @@ public class UserInfoTable { .column(ID, Sql.INT).primaryKey() .column(USER_ID, Sql.INT).notNull() .column(SERVER_ID, Sql.INT).notNull() - .column(JOIN_ADDRESS, Sql.varchar(255)) + .column(JOIN_ADDRESS, Sql.varchar(JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)) .column(REGISTERED, Sql.LONG).notNull() .column(OP, Sql.BOOL).notNull().defaultValue(false) .column(BANNED, Sql.BOOL).notNull().defaultValue(false) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java index d488fbd0c..78869e524 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/StoreJoinAddressTransaction.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.storage.database.queries.Query; import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable; import com.djrapitops.plan.storage.database.transactions.ExecStatement; import com.djrapitops.plan.storage.database.transactions.Transaction; +import org.apache.commons.lang3.StringUtils; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -53,18 +54,22 @@ public class StoreJoinAddressTransaction extends Transaction { return new HasMoreThanZeroQueryStatement(sql) { @Override public void prepare(PreparedStatement statement) throws SQLException { - String address = joinAddress.get(); - statement.setString(1, address.toLowerCase()); + String address = getAddress(); + statement.setString(1, address); } }; } + private String getAddress() { + return StringUtils.truncate(joinAddress.get().toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH); + } + @Override protected void performOperations() { execute(new ExecStatement(JoinAddressTable.INSERT_STATEMENT) { @Override public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, joinAddress.get().toLowerCase()); + statement.setString(1, getAddress()); } }); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java index ce3262cde..f9af6428e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/SessionJoinAddressPatch.java @@ -24,6 +24,7 @@ import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable; import com.djrapitops.plan.storage.database.sql.tables.SessionsTable; import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable; import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement; +import org.apache.commons.lang3.StringUtils; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -98,7 +99,7 @@ public class SessionJoinAddressPatch extends Patch { @Override public void prepare(PreparedStatement statement) throws SQLException { for (String joinAddress : joinAddresses) { - statement.setString(1, joinAddress.toLowerCase()); + statement.setString(1, StringUtils.truncate(joinAddress.toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)); statement.addBatch(); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/UserInfoHostnamePatch.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/UserInfoHostnamePatch.java index 3864f592b..b3d785d0d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/UserInfoHostnamePatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/UserInfoHostnamePatch.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.storage.database.transactions.patches; import com.djrapitops.plan.storage.database.sql.building.Sql; +import com.djrapitops.plan.storage.database.sql.tables.JoinAddressTable; import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable; /** @@ -34,6 +35,6 @@ public class UserInfoHostnamePatch extends Patch { @Override protected void applyPatch() { addColumn(UserInfoTable.TABLE_NAME, UserInfoTable.JOIN_ADDRESS + ' ' - + Sql.varchar(255)); + + Sql.varchar(JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH)); } } \ No newline at end of file