mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 16:37:58 +01:00
Increased Extension table value lengths to 250 chars
This commit is contained in:
parent
2da10001dc
commit
209530be4d
@ -26,6 +26,7 @@ import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -111,7 +112,7 @@ public class StorePlayerTableResultTransaction extends Transaction {
|
||||
statement.setString(2, playerUUID.toString());
|
||||
for (int i = 0; i < maxColumnSize; i++) {
|
||||
Object value = row[i];
|
||||
setStringOrNull(statement, 3 + i, value != null ? value.toString() : null);
|
||||
setStringOrNull(statement, 3 + i, value != null ? StringUtils.truncate(value.toString(), 250) : null);
|
||||
}
|
||||
// Rest are set null if not 4 columns wide.
|
||||
for (int i = maxColumnSize; i < 4; i++) {
|
||||
|
@ -26,6 +26,7 @@ import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -110,7 +111,7 @@ public class StoreServerTableResultTransaction extends Transaction {
|
||||
statement.setString(2, serverUUID.toString());
|
||||
for (int i = 0; i < maxColumnSize; i++) {
|
||||
Object value = row[i];
|
||||
setStringOrNull(statement, 3 + i, value != null ? value.toString() : null);
|
||||
setStringOrNull(statement, 3 + i, value != null ? StringUtils.truncate(value.toString(), 250) : null);
|
||||
}
|
||||
// Rest are set null if not 5 columns wide.
|
||||
for (int i = maxColumnSize; i < 5; i++) {
|
||||
|
@ -167,7 +167,8 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
new IPAnonPatch(),
|
||||
new BadAFKThresholdValuePatch(),
|
||||
new DeleteIPHashesPatch(),
|
||||
new ExtensionShowInPlayersTablePatch()
|
||||
new ExtensionShowInPlayersTablePatch(),
|
||||
new ExtensionTableRowValueLengthPatch()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,13 @@ package com.djrapitops.plan.storage.database.queries.schema;
|
||||
|
||||
import com.djrapitops.plan.storage.database.queries.HasMoreThanZeroQueryStatement;
|
||||
import com.djrapitops.plan.storage.database.queries.Query;
|
||||
import com.djrapitops.plan.storage.database.queries.QueryStatement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.SELECT;
|
||||
import static com.djrapitops.plan.storage.database.sql.parsing.Sql.*;
|
||||
|
||||
/**
|
||||
* Static method class for H2 Schema related queries.
|
||||
@ -56,4 +58,23 @@ public class H2SchemaQueries {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Integer> columnVarcharLength(String table, String column) {
|
||||
String sql = SELECT + "CHARACTER_MAXIMUM_LENGTH" +
|
||||
FROM + "INFORMATION_SCHEMA.COLUMNS " +
|
||||
WHERE + "TABLE_NAME=? AND COLUMN_NAME=?";
|
||||
|
||||
return new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, table);
|
||||
statement.setString(2, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getInt("CHARACTER_MAXIMUM_LENGTH") : Integer.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -109,6 +109,25 @@ public class MySQLSchemaQueries {
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Integer> columnVarcharLength(String table, String column) {
|
||||
String sql = SELECT + "CHARACTER_MAXIMUM_LENGTH" +
|
||||
FROM + "information_schema.COLUMNS" +
|
||||
WHERE + "TABLE_NAME=? AND COLUMN_NAME=? AND TABLE_SCHEMA=DATABASE()";
|
||||
|
||||
return new QueryStatement<Integer>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, table);
|
||||
statement.setString(2, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer processResults(ResultSet set) throws SQLException {
|
||||
return set.next() ? set.getInt("CHARACTER_MAXIMUM_LENGTH") : Integer.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a FOREIGN KEY constraint in a MySQL database.
|
||||
*
|
||||
|
@ -49,10 +49,10 @@ public class ExtensionPlayerTableValueTable {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(ID, INT).primaryKey()
|
||||
.column(USER_UUID, Sql.varchar(36)).notNull()
|
||||
.column(VALUE_1, Sql.varchar(50))
|
||||
.column(VALUE_2, Sql.varchar(50))
|
||||
.column(VALUE_3, Sql.varchar(50))
|
||||
.column(VALUE_4, Sql.varchar(50))
|
||||
.column(VALUE_1, Sql.varchar(250))
|
||||
.column(VALUE_2, Sql.varchar(250))
|
||||
.column(VALUE_3, Sql.varchar(250))
|
||||
.column(VALUE_4, Sql.varchar(250))
|
||||
.column(TABLE_ID, INT).notNull()
|
||||
.foreignKey(TABLE_ID, ExtensionTableProviderTable.TABLE_NAME, ExtensionPluginTable.ID)
|
||||
.build();
|
||||
|
@ -50,11 +50,11 @@ public class ExtensionServerTableValueTable {
|
||||
return CreateTableParser.create(TABLE_NAME, dbType)
|
||||
.column(ID, INT).primaryKey()
|
||||
.column(SERVER_UUID, Sql.varchar(36)).notNull()
|
||||
.column(VALUE_1, Sql.varchar(50))
|
||||
.column(VALUE_2, Sql.varchar(50))
|
||||
.column(VALUE_3, Sql.varchar(50))
|
||||
.column(VALUE_4, Sql.varchar(50))
|
||||
.column(VALUE_5, Sql.varchar(50))
|
||||
.column(VALUE_1, Sql.varchar(250))
|
||||
.column(VALUE_2, Sql.varchar(250))
|
||||
.column(VALUE_3, Sql.varchar(250))
|
||||
.column(VALUE_4, Sql.varchar(250))
|
||||
.column(VALUE_5, Sql.varchar(250))
|
||||
.column(TABLE_ID, INT).notNull()
|
||||
.foreignKey(TABLE_ID, ExtensionTableProviderTable.TABLE_NAME, ExtensionPluginTable.ID)
|
||||
.build();
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database.transactions.patches;
|
||||
|
||||
import com.djrapitops.plan.storage.database.DBType;
|
||||
import com.djrapitops.plan.storage.database.queries.schema.H2SchemaQueries;
|
||||
import com.djrapitops.plan.storage.database.queries.schema.MySQLSchemaQueries;
|
||||
import com.djrapitops.plan.storage.database.sql.parsing.Sql;
|
||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionPlayerTableValueTable;
|
||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionServerTableValueTable;
|
||||
|
||||
public class ExtensionTableRowValueLengthPatch extends Patch {
|
||||
|
||||
private String playerTable;
|
||||
private String serverTable;
|
||||
|
||||
public ExtensionTableRowValueLengthPatch() {
|
||||
playerTable = ExtensionPlayerTableValueTable.TABLE_NAME;
|
||||
serverTable = ExtensionServerTableValueTable.TABLE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return dbType == DBType.SQLITE || // SQLite does not limit varchar lengths
|
||||
(columnVarcharLength(playerTable, ExtensionPlayerTableValueTable.VALUE_4) >= 250
|
||||
&& columnVarcharLength(serverTable, ExtensionServerTableValueTable.VALUE_5) >= 250);
|
||||
}
|
||||
|
||||
private int columnVarcharLength(String table, String column) {
|
||||
if (dbType == DBType.MYSQL) {
|
||||
return query(MySQLSchemaQueries.columnVarcharLength(table, column));
|
||||
} else {
|
||||
return query(H2SchemaQueries.columnVarcharLength(table, column));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
increaseLength(playerTable, ExtensionPlayerTableValueTable.VALUE_1);
|
||||
increaseLength(playerTable, ExtensionPlayerTableValueTable.VALUE_2);
|
||||
increaseLength(playerTable, ExtensionPlayerTableValueTable.VALUE_3);
|
||||
increaseLength(playerTable, ExtensionPlayerTableValueTable.VALUE_4);
|
||||
|
||||
increaseLength(serverTable, ExtensionServerTableValueTable.VALUE_1);
|
||||
increaseLength(serverTable, ExtensionServerTableValueTable.VALUE_2);
|
||||
increaseLength(serverTable, ExtensionServerTableValueTable.VALUE_3);
|
||||
increaseLength(serverTable, ExtensionServerTableValueTable.VALUE_4);
|
||||
increaseLength(serverTable, ExtensionServerTableValueTable.VALUE_5);
|
||||
}
|
||||
|
||||
private void increaseLength(String table, String column) {
|
||||
execute("ALTER TABLE " + table + " MODIFY " + column + " " + Sql.varchar(250));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user