diff options
Diffstat (limited to 'src/com/juick')
-rw-r--r-- | src/com/juick/server/MessagesQueries.java | 25 | ||||
-rw-r--r-- | src/com/juick/server/TagQueries.java | 2 | ||||
-rw-r--r-- | src/com/juick/server/UserQueries.java | 2 |
3 files changed, 15 insertions, 14 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) { diff --git a/src/com/juick/server/TagQueries.java b/src/com/juick/server/TagQueries.java index 55704eac..e4d94121 100644 --- a/src/com/juick/server/TagQueries.java +++ b/src/com/juick/server/TagQueries.java @@ -154,7 +154,7 @@ public class TagQueries { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT tags.name FROM tags INNER JOIN bl_tags ON (bl_tags.user_id=? AND bl_tags.tag_id=tags.tag_id)"); + stmt = sql.prepareStatement("SELECT tags.name FROM tags INNER JOIN bl_tags ON (bl_tags.user_id=? AND bl_tags.tag_id=tags.tag_id) ORDER BY tags.name"); stmt.setInt(1, uid); rs = stmt.executeQuery(); rs.beforeFirst(); diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index 1933f26a..186cacc9 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -527,7 +527,7 @@ public class UserQueries { PreparedStatement stmt = null; ResultSet rs = null; try { - stmt = sql.prepareStatement("SELECT users.id,users.nick FROM users INNER JOIN bl_users ON(bl_users.bl_user_id=users.id) WHERE bl_users.user_id=?"); + stmt = sql.prepareStatement("SELECT users.id,users.nick FROM users INNER JOIN bl_users ON(bl_users.bl_user_id=users.id) WHERE bl_users.user_id=? ORDER BY users.nick"); stmt.setInt(1, uid); rs = stmt.executeQuery(); rs.beforeFirst(); |