aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-07-25 00:16:47 +0700
committerGravatar Ugnich Anton2014-07-25 00:16:47 +0700
commit13a861563ffead4cadba48e523aad2e5c6beb44c (patch)
tree0f60efcdfc498d631cf1ea782366f4d212238093 /src/com/juick
parentb67b2f126af0c410cdb5b1a925d19b5d2cc5b2b2 (diff)
AdsQueries for unauthorized
Diffstat (limited to 'src/com/juick')
-rw-r--r--src/com/juick/server/AdsQueries.java6
-rw-r--r--src/com/juick/server/SQLHelpers.java18
2 files changed, 23 insertions, 1 deletions
diff --git a/src/com/juick/server/AdsQueries.java b/src/com/juick/server/AdsQueries.java
index f1b37fb1..0fb4c0a6 100644
--- a/src/com/juick/server/AdsQueries.java
+++ b/src/com/juick/server/AdsQueries.java
@@ -28,7 +28,11 @@ import java.sql.SQLException;
public class AdsQueries {
public static int getAdMID(Connection sql, int uid) {
- return SQLHelpers.getInt(sql, "SELECT message_id FROM ads_messages WHERE message_id NOT IN (SELECT message_id FROM ads_messages_log WHERE user_id=? AND ts>UNIX_TIMESTAMP()-60*60*24 GROUP BY message_id HAVING COUNT(*)>2) ORDER BY RAND() LIMIT 1", uid, 0);
+ if (uid > 0) {
+ return SQLHelpers.getInt(sql, "SELECT message_id FROM ads_messages WHERE message_id NOT IN (SELECT message_id FROM ads_messages_log WHERE user_id=? AND ts>UNIX_TIMESTAMP()-60*60*24 GROUP BY message_id HAVING COUNT(*)>2) ORDER BY RAND() LIMIT 1", uid, 0);
+ } else {
+ return SQLHelpers.getInt(sql, "SELECT message_id FROM ads_messages ORDER BY RAND() LIMIT 1", 0);
+ }
}
public static void logAdMID(Connection sql, int uid, int mid) {
diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java
index 28ccdb8c..f5569993 100644
--- a/src/com/juick/server/SQLHelpers.java
+++ b/src/com/juick/server/SQLHelpers.java
@@ -45,6 +45,24 @@ public class SQLHelpers {
return ret;
}
+ public static int getInt(Connection sql, String query, int defvalue) {
+ int ret = defvalue;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = sql.prepareStatement(query);
+ rs = stmt.executeQuery();
+ if (rs.first()) {
+ ret = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ System.err.println(e);
+ } finally {
+ Utils.finishSQL(rs, stmt);
+ }
+ return ret;
+ }
+
public static int getInt(Connection sql, String query, int param, int defvalue) {
int ret = defvalue;
PreparedStatement stmt = null;