Fixed MySQL with multiple plan databases returns wrong table count #724

This commit is contained in:
Rsl1122 2018-09-08 17:15:50 +03:00
parent ac3e9a969c
commit 2c5a97d0b1
2 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser; import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
import com.djrapitops.plan.system.settings.Settings;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -29,13 +30,16 @@ public abstract class Patch {
public boolean hasTable(String tableName) { public boolean hasTable(String tableName) {
String sql = usingMySQL ? String sql = usingMySQL ?
"SELECT * FROM information_schema.TABLES WHERE table_name=? LIMIT 1" : "SELECT * FROM information_schema.TABLES WHERE table_name=? AND TABLE_SCHEMA=? LIMIT 1" :
"SELECT tbl_name FROM sqlite_master WHERE tbl_name=?"; "SELECT tbl_name FROM sqlite_master WHERE tbl_name=?";
return query(new QueryStatement<Boolean>(sql) { return query(new QueryStatement<Boolean>(sql) {
@Override @Override
public void prepare(PreparedStatement statement) throws SQLException { public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, tableName); statement.setString(1, tableName);
if (usingMySQL) {
statement.setString(2, Settings.DB_DATABASE.toString());
}
} }
@Override @Override

View File

@ -10,7 +10,7 @@ public class VersionTableRemovalPatch extends Patch {
@Override @Override
public boolean hasBeenApplied() { public boolean hasBeenApplied() {
return hasTable("plan_version"); return !hasTable("plan_version");
} }
@Override @Override