diff options
author | Ugnich Anton | 2013-06-20 18:22:12 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-06-20 18:22:12 +0700 |
commit | a1ecda62eef3b802dbfa044f75ec0050de6ba75e (patch) | |
tree | d8d0ec6cc221cd6f0f4b034c85f47f5ef8eac5dd /src | |
parent | de81a033905d1c4cd18ac9b5af8a7f8fb853b121 (diff) |
SQLHelpers.getArrayInteger
Users.getUserRead
Users.getUserReaders
Diffstat (limited to 'src')
-rw-r--r-- | src/com/juick/server/MessagesQueries.java | 8 | ||||
-rw-r--r-- | src/com/juick/server/SQLHelpers.java | 40 | ||||
-rw-r--r-- | src/com/juick/server/UserQueries.java | 10 |
3 files changed, 53 insertions, 5 deletions
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java index 42b45c24..55fc3898 100644 --- a/src/com/juick/server/MessagesQueries.java +++ b/src/com/juick/server/MessagesQueries.java @@ -283,11 +283,11 @@ public class MessagesQueries { ResultSet rs = null; try { if (before > 0) { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND (privacy>0 OR user_id=?) AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE message_id<? AND (privacy>0 OR user_id=?) AND lang='ru' ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, before); stmt.setInt(2, visitor_uid); } else { - stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang!='fa' ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages WHERE (privacy>0 OR user_id=?) AND lang='ru' ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, visitor_uid); } rs = stmt.executeQuery(); @@ -367,13 +367,13 @@ public class MessagesQueries { ResultSet rs = null; try { if (before > 0) { - stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE message_id<? AND privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE message_id<? AND (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, uid); stmt.setInt(2, before); stmt.setInt(3, uid); stmt.setInt(4, uid); } else { - stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?)) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20"); + stmt = sql.prepareStatement("SELECT message_id FROM messages INNER JOIN subscr_users ON (subscr_users.suser_id=? AND subscr_users.user_id=messages.user_id) WHERE (privacy>=0 OR (privacy>=-2 AND privacy<=-1 AND messages.user_id IN (SELECT user_id FROM wl_users WHERE wl_user_id=?))) AND message_id NOT IN (SELECT message_id FROM messages_tags WHERE tag_id IN (SELECT tag_id FROM bl_tags WHERE user_id=?)) ORDER BY message_id DESC LIMIT 20"); stmt.setInt(1, uid); stmt.setInt(2, uid); stmt.setInt(3, uid); diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java new file mode 100644 index 00000000..dd83a915 --- /dev/null +++ b/src/com/juick/server/SQLHelpers.java @@ -0,0 +1,40 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +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 SQLHelpers { + + public static ArrayList<Integer> getArrayInteger(Connection sql, String query, int param) { + ArrayList<Integer> ret = new ArrayList<Integer>(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement(query); + stmt.setInt(1, param); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + ret.add(rs.getInt(1)); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + + return ret; + } +} diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index a9f00f94..652809d6 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -64,7 +64,7 @@ public class UserQueries { } finally { Utils.finishSQL(null, stmt); } - + return uid; } @@ -358,6 +358,14 @@ public class UserQueries { return ret; } + public static ArrayList<Integer> getUserRead(Connection sql, int uid) { + return SQLHelpers.getArrayInteger(sql, "SELECT user_id FROM subscr_users WHERE suser_id=?", uid); + } + + public static ArrayList<Integer> getUserReaders(Connection sql, int uid) { + return SQLHelpers.getArrayInteger(sql, "SELECT suser_id FROM subscr_users WHERE user_id=?", uid); + } + public static int getStatsIRead(Connection sql, int uid) { int ret = 0; PreparedStatement stmt = null; |