Files
Server/src/engine/db/handlers/dbStaticWorldHandler.java
T

47 lines
2.0 KiB
Java
Raw Normal View History

// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
package engine.db.handlers;
import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class dbStaticWorldHandler extends dbHandlerBase {
public dbStaticWorldHandler() {
}
// Table and column come from StaticManifest's fixed list, never from input. -1 means "none" and is skipped.
public HashMap<Integer, Integer> GET_NEGATIVE_REFERENCES(String table, String column) {
HashMap<Integer, Integer> rowsByValue = new HashMap<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `" + column + "` AS `value`, COUNT(*) AS `rows` FROM `"
+ table + "` WHERE `" + column + "` < -1 GROUP BY `" + column + "`;")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next())
rowsByValue.put(rs.getInt("value"), rs.getInt("rows"));
} catch (SQLException e) {
Logger.error(table + "." + column + ": " + e);
return null;
}
return rowsByValue;
}
}