mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 15:56:00 +08:00
Reduce join_address column length to 250 characters
- Add error code 1071 to error definition Affects issues: - Possibly fixed #2477
This commit is contained in:
parent
85321899ad
commit
47bc49a0d2
@ -142,6 +142,10 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
|
|||||||
context.related(CONSTRAINT_VIOLATION)
|
context.related(CONSTRAINT_VIOLATION)
|
||||||
.whatToDo("Report this error. NOT NULL constraint violation occurred.");
|
.whatToDo("Report this error. NOT NULL constraint violation occurred.");
|
||||||
break;
|
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:
|
default:
|
||||||
context.related("Unknown SQL Error code");
|
context.related("Unknown SQL Error code");
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public class DataStoreQueries {
|
|||||||
statement.setLong(2, registered);
|
statement.setLong(2, registered);
|
||||||
statement.setString(3, serverUUID.toString());
|
statement.setString(3, serverUUID.toString());
|
||||||
statement.setBoolean(4, false); // Banned
|
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
|
statement.setBoolean(6, false); // Operator
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,8 @@ public class JoinAddressTable {
|
|||||||
public static final String TABLE_NAME = "plan_join_address";
|
public static final String TABLE_NAME = "plan_join_address";
|
||||||
public static final String ID = "id";
|
public static final String ID = "id";
|
||||||
public static final String JOIN_ADDRESS = "join_address";
|
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 SELECT_ID = '(' + SELECT + ID + FROM + TABLE_NAME + WHERE + JOIN_ADDRESS + "=LOWER(?))";
|
||||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME +
|
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME +
|
||||||
" (" + JOIN_ADDRESS + ") VALUES (LOWER(?))";
|
" (" + JOIN_ADDRESS + ") VALUES (LOWER(?))";
|
||||||
@ -37,7 +39,7 @@ public class JoinAddressTable {
|
|||||||
public static String createTableSQL(DBType dbType) {
|
public static String createTableSQL(DBType dbType) {
|
||||||
return CreateTableBuilder.create(TABLE_NAME, dbType)
|
return CreateTableBuilder.create(TABLE_NAME, dbType)
|
||||||
.column(ID, Sql.INT).primaryKey()
|
.column(ID, Sql.INT).primaryKey()
|
||||||
.column(JOIN_ADDRESS, Sql.varchar(255)).unique()
|
.column(JOIN_ADDRESS, Sql.varchar(JOIN_ADDRESS_MAX_LENGTH)).unique()
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public class UserInfoTable {
|
|||||||
.column(ID, Sql.INT).primaryKey()
|
.column(ID, Sql.INT).primaryKey()
|
||||||
.column(USER_ID, Sql.INT).notNull()
|
.column(USER_ID, Sql.INT).notNull()
|
||||||
.column(SERVER_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(REGISTERED, Sql.LONG).notNull()
|
||||||
.column(OP, Sql.BOOL).notNull().defaultValue(false)
|
.column(OP, Sql.BOOL).notNull().defaultValue(false)
|
||||||
.column(BANNED, Sql.BOOL).notNull().defaultValue(false)
|
.column(BANNED, Sql.BOOL).notNull().defaultValue(false)
|
||||||
|
@ -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.sql.tables.JoinAddressTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -53,18 +54,22 @@ public class StoreJoinAddressTransaction extends Transaction {
|
|||||||
return new HasMoreThanZeroQueryStatement(sql) {
|
return new HasMoreThanZeroQueryStatement(sql) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
String address = joinAddress.get();
|
String address = getAddress();
|
||||||
statement.setString(1, address.toLowerCase());
|
statement.setString(1, address);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getAddress() {
|
||||||
|
return StringUtils.truncate(joinAddress.get().toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
execute(new ExecStatement(JoinAddressTable.INSERT_STATEMENT) {
|
execute(new ExecStatement(JoinAddressTable.INSERT_STATEMENT) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setString(1, joinAddress.get().toLowerCase());
|
statement.setString(1, getAddress());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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.SessionsTable;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
|
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -98,7 +99,7 @@ public class SessionJoinAddressPatch extends Patch {
|
|||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
for (String joinAddress : joinAddresses) {
|
for (String joinAddress : joinAddresses) {
|
||||||
statement.setString(1, joinAddress.toLowerCase());
|
statement.setString(1, StringUtils.truncate(joinAddress.toLowerCase(), JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH));
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package com.djrapitops.plan.storage.database.transactions.patches;
|
package com.djrapitops.plan.storage.database.transactions.patches;
|
||||||
|
|
||||||
import com.djrapitops.plan.storage.database.sql.building.Sql;
|
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;
|
import com.djrapitops.plan.storage.database.sql.tables.UserInfoTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +35,6 @@ public class UserInfoHostnamePatch extends Patch {
|
|||||||
@Override
|
@Override
|
||||||
protected void applyPatch() {
|
protected void applyPatch() {
|
||||||
addColumn(UserInfoTable.TABLE_NAME, UserInfoTable.JOIN_ADDRESS + ' '
|
addColumn(UserInfoTable.TABLE_NAME, UserInfoTable.JOIN_ADDRESS + ' '
|
||||||
+ Sql.varchar(255));
|
+ Sql.varchar(JoinAddressTable.JOIN_ADDRESS_MAX_LENGTH));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user