Fixes Clean SQLException of TPS Table

This commit is contained in:
Rsl1122 2017-09-02 12:51:40 +03:00
parent e8cc93ea21
commit 6ddaf8dec8

View File

@ -132,12 +132,18 @@ public class TPSTable extends Table {
* @throws SQLException * @throws SQLException
*/ */
public void clean() throws SQLException { public void clean() throws SQLException {
Optional<TPS> allTimePeak = getAllTimePeak();
int p = -1;
if (allTimePeak.isPresent()) {
p = allTimePeak.get().getPlayers();
}
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = prepareStatement("DELETE FROM " + tableName + statement = prepareStatement("DELETE FROM " + tableName +
" WHERE (" + columnDate + "<?)" + " WHERE (" + columnDate + "<?)" +
" AND (" + columnPlayers + "" + " AND (" + columnPlayers + "" +
" != (SELECT MAX(" + columnPlayers + ") FROM " + tableName + "))"); " != ?)");
statement.setInt(1, p);
// More than 2 Months ago. // More than 2 Months ago.
long fiveWeeks = TimeAmount.MONTH.ms() * 2L; long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
statement.setLong(1, MiscUtils.getTime() - fiveWeeks); statement.setLong(1, MiscUtils.getTime() - fiveWeeks);