aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/server/MessagesQueries.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2014-04-20 15:16:16 +0700
committerGravatar Ugnich Anton2014-04-20 15:16:16 +0700
commit29df00e4fa77ba4aeda0b9780e30c17dd57d92b2 (patch)
tree60b1485ba99ff52485f2f06964cdeb80d2ab378b /src/com/juick/server/MessagesQueries.java
parentf9ee0de56d757ecfe22db0611140f29d640cef3a (diff)
BL lists order, create reply bugfix
Diffstat (limited to 'src/com/juick/server/MessagesQueries.java')
-rw-r--r--src/com/juick/server/MessagesQueries.java25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/com/juick/server/MessagesQueries.java b/src/com/juick/server/MessagesQueries.java
index cf2dd04d..550da56d 100644
--- a/src/com/juick/server/MessagesQueries.java
+++ b/src/com/juick/server/MessagesQueries.java
@@ -38,7 +38,7 @@ public class MessagesQueries {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
- stmt = sql.prepareStatement("INSERT INTO messages(user_id,attachment) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
+ stmt = sql.prepareStatement("INSERT INTO messages(user_id,attach) VALUES (?,?)", Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, uid);
if (attachment != null) {
stmt.setString(2, attachment);
@@ -95,13 +95,13 @@ public class MessagesQueries {
}
public static int createReply(Connection sql, int mid, int rid, int uid, String txt, String attachment) {
- int newrid = getReplyIDIncrement(sql, mid);
+ int ridnew = getReplyIDIncrement(sql, mid);
PreparedStatement stmt = null;
try {
stmt = sql.prepareStatement("INSERT INTO replies(message_id,reply_id,user_id,replyto,attach,txt) VALUES (?,?,?,?,?,?)");
stmt.setInt(1, mid);
- stmt.setInt(2, newrid);
+ stmt.setInt(2, ridnew);
stmt.setInt(3, uid);
stmt.setInt(4, rid);
if (attachment != null) {
@@ -111,7 +111,7 @@ public class MessagesQueries {
}
stmt.setString(6, txt);
if (stmt.executeUpdate() == 0) {
- newrid = 0;
+ ridnew = 0;
}
} catch (SQLException e) {
System.err.println(e);
@@ -119,22 +119,23 @@ public class MessagesQueries {
Utils.finishSQL(null, stmt);
}
- return newrid;
+ if (ridnew > 0) {
+ SQLHelpers.executeInt(sql, "UPDATE messages SET replies=replies+1 WHERE message_id=?", mid);
+ }
+
+ return ridnew;
}
public static int getReplyIDIncrement(Connection sql, int mid) {
- int ret = 0;
+ int rid = 0;
SQLHelpers.execute(sql, "LOCK TABLES messages WRITE");
-
- int rid = SQLHelpers.getInt(sql, "SELECT maxreplyid FROM messages WHERE message_id=?", mid, -1);
- if (rid >= 0 && SQLHelpers.executeInt(sql, "UPDATE messages SET maxreplyid=maxreplyid+1 WHERE message_id=?", mid) == 1) {
- ret = rid + 1;
+ if (SQLHelpers.executeInt(sql, "UPDATE messages SET maxreplyid=maxreplyid+1 WHERE message_id=?", mid) == 1) {
+ rid = SQLHelpers.getInt(sql, "SELECT maxreplyid FROM messages WHERE message_id=?", mid, 0);
}
-
SQLHelpers.execute(sql, "UNLOCK TABLES");
- return ret;
+ return rid;
}
public static boolean canViewThread(Connection sql, int mid, int uid) {