 ) \
 WHERE LINENUM >= ? AND LINENUM < ?
 
+# #############
+# PollModel
+# #############
+PollModel.addNewPoll = INSERT INTO jforum_vote_desc (vote_id, topic_id, vote_text, vote_length, vote_start) \
+	VALUES (jforum_vote_desc_seq.nextval, ?, ?, ?, SYSDATE)
+	
+PollModel.lastGeneratedPollId = SELECT jforum_vote_desc_seq.currval FROM DUAL
+
+# #############
+# ForumModel
+# #############
+ForumModel.addNew = INSERT INTO jforum_forums (forum_id, categories_id, forum_name, forum_desc, forum_order, moderated) VALUES (jforum_forums_seq.nextval, ?, ?, ?, ?, ?)
+ForumModel.lastGeneratedForumId = SELECT jforum_forums_seq.currval FROM DUAL
+ForumModel.statsFirstPostTime = SELECT MIN(post_time) FROM jforum_posts
+ForumModel.statsFirstRegisteredUserTime = SELECT MIN(user_regdate) FROM jforum_users
+
+# #############
+# TopicModel
+# #############
+TopicModel.addNew = INSERT INTO jforum_topics (topic_id, forum_id, topic_title, user_id, topic_time, topic_first_post_id, topic_last_post_id, topic_type, moderated) \
+	VALUES (jforum_topics_seq.nextval, ?, ?, ?, ?, ?, ?, ?, ?)
+
+##########################################################################################
+# Ignores attachements (0 as attach), but goes two orders of magnitude higher...
+##########################################################################################
+TopicModel.selectAllByForumByLimit = SELECT * FROM ( \
+       SELECT t.*, p.user_id AS last_user_id, p.post_time, (SELECT SUM(p.attach) \
+        FROM jforum_posts p \
+        WHERE p.topic_id = t.topic_id \
+        AND p.need_moderate = 0) AS attach, \
+       ROW_NUMBER() OVER(ORDER BY topic_type DESC, topic_last_post_id DESC) - 1 LINENUM \
+       FROM jforum_topics t, jforum_posts p \
+       WHERE (t.forum_id = ? OR t.topic_moved_id = ?) \
+       AND p.post_id = t.topic_last_post_id \
+       AND p.need_moderate = 0 \
+	) \
+	WHERE LINENUM >= ? AND LINENUM < ?
+
 TopicModel.selectByUserByLimit = SELECT * FROM ( \
-    SELECT t.*, p.user_id AS last_user_id, p.post_time, 0 AS attach, \
+    SELECT t.*, p.user_id AS last_user_id, p.post_time, (SELECT SUM(p.attach) \
+        FROM jforum_posts p \
+        WHERE p.topic_id = t.topic_id \
+        AND p.need_moderate = 0) AS attach, \
     ROW_NUMBER() OVER(ORDER BY topic_last_post_id ASC) - 1 LINENUM \
 	FROM jforum_topics t, jforum_posts p \
 	WHERE p.post_id = t.topic_last_post_id \

	
PostModel.selectHotForRSS = SELECT * FROM ( \
		SELECT t.topic_id, t.topic_title AS subject, p.post_id, t.forum_id, pt.post_text, p.post_time, p.user_id, u.username, \
		ROW_NUMBER() OVER(ORDER BY topic_first_post_id DESC) \
		FROM jforum_topics t, jforum_posts p, jforum_posts_text pt, jforum_users u \
		WHERE p.post_id = t.topic_first_post_id \
		AND p.topic_id = t.topic_id \

UserModel.addNew = INSERT INTO jforum_users (user_id, username, user_password, user_email, user_regdate, user_actkey, rank_id) VALUES (jforum_users_seq.nextval, ?, ?, ?, ?, ?, 0)

UserModel.selectAllByLimit = SELECT * FROM ( \
        SELECT user_email, user_id, user_posts, user_regdate, username, deleted, user_karma, user_from, user_website, user_viewemail, ROW_NUMBER() OVER(ORDER BY username) - 1 LINENUM \
        FROM jforum_users ORDER BY username \
        ) \
        WHERE LINENUM >= ? AND LINENUM < ?
