From ae4f9f1759dafdc1bf57e043450970794954324d Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sun, 9 Mar 2014 00:56:39 +0700 Subject: -messages.lang -VotesQueries --- src/com/juick/server/MessagesQueries.java | 16 +++--- src/com/juick/server/VotesQueries.java | 91 ------------------------------- 2 files changed, 8 insertions(+), 99 deletions(-) delete mode 100644 src/com/juick/server/VotesQueries.java (limited to 'src') diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java index dd284d3f..3dd8418b 100644 --- a/src/com/juick/server/MessagesQueries.java +++ b/src/com/juick/server/MessagesQueries.java @@ -130,7 +130,7 @@ public class MessagesQueries { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT messages.user_id,users.nick,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.readonly,messages.privacy,messages.replies,messages.attach,messages.place_id,messages.lat,messages.lon,messages.votes FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id=?"); + stmt = sql.prepareStatement("SELECT messages.user_id,users.nick,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.readonly,messages.privacy,messages.replies,messages.attach,messages.place_id,messages.lat,messages.lon,messages.likes FROM messages INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id=?"); stmt.setInt(1, mid); rs = stmt.executeQuery(); if (rs.first()) { @@ -154,7 +154,7 @@ public class MessagesQueries { msg.Place.lat = rs.getDouble(10); msg.Place.lon = rs.getDouble(11); } - msg.Votes = rs.getInt(12); + msg.Likes = rs.getInt(12); } } catch (SQLException e) { System.err.println(e); @@ -291,21 +291,21 @@ public class MessagesQueries { try { if (visitor_uid > 1) { if (before > 0) { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 OR user_id=?) AND lang!='fa' AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, before); stmt.setInt(2, visitor_uid); stmt.setInt(3, visitor_uid); } else { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang!='fa' AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND user_id NOT IN (SELECT bl_user_id FROM bl_users WHERE user_id=?) ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, visitor_uid); stmt.setInt(2, visitor_uid); } } else { if (before > 0) { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id0 ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, before); } else { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE privacy>0 ORDER BY message_id DESC LIMIT 20"); } } @@ -811,7 +811,7 @@ public class MessagesQueries { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.replies,messages_txt.repliesby,messages.attach,messages.lat,messages.lon,messages.votes FROM (messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id IN (" + Utils.convertArrayInt2String(mids) + ") ORDER BY messages.message_id DESC"); + stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),DATE_FORMAT(messages.ts,'%Y-%m-%d %H:%i:%s'),messages.replies,messages_txt.repliesby,messages.attach,messages.lat,messages.lon,messages.likes FROM (messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id WHERE messages.message_id IN (" + Utils.convertArrayInt2String(mids) + ") ORDER BY messages.message_id DESC"); rs = stmt.executeQuery(); rs.beforeFirst(); while (rs.next()) { @@ -838,7 +838,7 @@ public class MessagesQueries { msg.Place.lat = rs.getDouble(13); msg.Place.lon = rs.getDouble(14); } - msg.Votes = rs.getInt(15); + msg.Likes = rs.getInt(15); msgs.add(msg); } diff --git a/src/com/juick/server/VotesQueries.java b/src/com/juick/server/VotesQueries.java deleted file mode 100644 index d3af99c1..00000000 --- a/src/com/juick/server/VotesQueries.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.juick.server; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; - -/** - * - * @author ugnich - */ -public class VotesQueries { - - public static boolean voteMessage(Connection sql, int mid, int uid, int vote) { - boolean ret = false; - - PreparedStatement stmt = null; - try { - stmt = sql.prepareStatement("INSERT INTO messages_votes(message_id,user_id,vote) VALUES (?,?,?)"); - stmt.setInt(1, mid); - stmt.setInt(2, uid); - stmt.setInt(3, vote); - ret = stmt.executeUpdate() > 0; - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(null, stmt); - } - - if (ret) { - try { - String query; - if (vote > 0) { - query = "UPDATE messages SET votes=votes+1 WHERE message_id=?"; - } else { - query = "UPDATE messages SET votes=votes-1 WHERE message_id=?"; - } - stmt = sql.prepareStatement(query); - stmt.setInt(1, mid); - stmt.executeUpdate(); - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(null, stmt); - } - } - - return ret; - } - - public static int getMessageVotes(Connection sql, int mid) { - return SQLHelpers.getInt(sql, "SELECT votes FROM messages WHERE message_id=?", mid, 0); - } - - public static boolean fillMessagesVotes(Connection sql, ArrayList msgs, int vuid) { - boolean ret = false; - - String mids = ""; - final int midsSize = msgs.size(); - for (int i = 0; i < midsSize; i++) { - if (i > 0) { - mids += ","; - } - mids += msgs.get(i).MID; - } - - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT message_id,vote FROM messages_votes WHERE user_id=? AND message_id IN (" + mids + ")"); - stmt.setInt(1, vuid); - rs = stmt.executeQuery(); - rs.beforeFirst(); - while (rs.next()) { - int mid = rs.getInt(1); - for (int i = 0; i < midsSize; i++) { - if (msgs.get(i).MID == mid) { - msgs.get(i).UserVote = rs.getInt(2); - ret = true; - } - } - } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); - } - return ret; - } -} -- cgit v1.2.3