Merge pull request #519 from t00thpick1/patch-2

Fix discrepencies between mctop and mcrank in sql
This commit is contained in:
Glitchfinder 2013-01-15 18:37:34 -08:00
commit 65f78ba447

View File

@ -425,19 +425,19 @@ public class Database {
if (checkConnected()) { if (checkConnected()) {
try { try {
String sql = "SELECT " String sql = "SELECT "
+ "(SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing > (SELECT s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'ALL'" + "(SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'ALL'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.fishing > (SELECT s.fishing FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'FISHING'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.fishing desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'FISHING'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.taming > (SELECT s.taming FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'TAMING'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.taming desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'TAMING'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.woodcutting > (SELECT s.woodcutting FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'WOODCUTTING'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.woodcutting desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'WOODCUTTING'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.repair > (SELECT s.repair FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'REPAIR'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.repair desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'REPAIR'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.unarmed > (SELECT s.unarmed FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'UNARMED'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.unarmed desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'UNARMED'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.herbalism > (SELECT s.herbalism FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'HERBALISM'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.herbalism desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'HERBALISM'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.excavation > (SELECT s.excavation FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'EXCAVATION'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.excavation desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'EXCAVATION'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.archery > (SELECT s.archery FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'ARCHERY'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.archery desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'ARCHERY'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.swords > (SELECT s.swords FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'SWORDS'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.swords desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'SWORDS'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.axes > (SELECT s.axes FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'AXES'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.axes desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'AXES'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.acrobatics > (SELECT s.acrobatics FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'ACROBATICS'" + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.acrobatics desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'ACROBATICS'"
+ ", (SELECT COUNT(*) AS rank FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE u.id = s.user_id AND s.mining > (SELECT s.mining FROM " + tablePrefix + "skills as s, " + tablePrefix + "users as u WHERE u.id = s.user_id AND u.user = '" + playerName + "')) AS 'MINING'"; + ", (SELECT rank FROM (SELECT @rownum:=@rownum+1 rank, p.user AS user FROM (SELECT @rownum:=0) AS rank, ((SELECT u.user AS user FROM " + tablePrefix + "users u, " + tablePrefix + "skills s WHERE u.id = s.user_id ORDER BY s.mining desc ) AS p) AS d) WHERE user = '" + playerName + "') AS 'MINING'";
PreparedStatement statement = connection.prepareStatement(sql); PreparedStatement statement = connection.prepareStatement(sql);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {