Ticket #790: discussion-plugin-r1491-sqlite-2.8.16.patch
| File discussion-plugin-r1491-sqlite-2.8.16.patch, 8.6 kB (added by sto, 2 years ago) |
|---|
-
0.10/tracdiscussion/api.py
old new 777 777 if order_by != 'forum': 778 778 order_by = 'g.' + order_by 779 779 columns = ('id', 'name', 'description', 'forums') 780 sql = "SELECT g.id, g.name, g.description, (SELECT COUNT(f.id)" \ 781 " FROM forum f, forum_group g WHERE f.forum_group = g.id) AS" \ 782 " forums FROM forum_group g ORDER BY " + order_by + (" ASC", 780 sql = "SELECT g.id, g.name, g.description, f.forums FROM " \ 781 " forum_group g LEFT JOIN (SELECT COUNT(id) AS forums, " \ 782 " forum_group FROM forum GROUP BY forum_group) f ON g.id = " \ 783 " f.forum_group ORDER BY " + order_by + (" ASC", 783 784 " DESC")[bool(desc)] 784 785 self.log.debug(sql) 785 786 cursor.execute(sql) … … 797 798 'subject', 'description', 'topics', 'replies', 'lastreply', 798 799 'lasttopic') 799 800 sql = "SELECT f.id, f.name, f.author, f.time, f.moderators," \ 800 " f.forum_group, f.subject, f.description, (SELECT COUNT(t.id)" \ 801 " FROM topic t, forum f WHERE t.forum = f.id) AS topics, (SELECT" \ 802 " COUNT(m.id) FROM message m, forum f WHERE m.forum = f.id) AS" \ 803 " replies, (SELECT MAX(m.time) FROM message m, forum f WHERE" \ 804 " m.forum = f.id) AS lasttopic, (SELECT MAX(t.time) FROM topic t," \ 805 " forum f WHERE t.forum = f.id) AS lastreply FROM forum f ORDER BY " \ 801 " f.forum_group, f.subject, f.description, tm.topics, tm.replies," \ 802 " tm.lastreply, tm.lasttopic FROM forum f LEFT JOIN ( SELECT" \ 803 " tf.forum AS forum, topics, lasttopic, replies, lastreply FROM" \ 804 " (SELECT COUNT(id) AS topics, MAX(time) AS lasttopic, forum" \ 805 " FROM topic GROUP BY forum) tf, (SELECT COUNT(id) AS replies," \ 806 " MAX(time) AS lastreply, forum FROM message GROUP BY forum) mf" \ 807 " WHERE tf.forum = mf.forum) tm ON f.id = tm.forum ORDER BY " \ 806 808 + order_by + (" ASC", " DESC")[bool(desc)] 807 809 self.log.debug(sql) 808 810 cursor.execute(sql) … … 812 814 row['moderators'] = wiki_to_oneliner(row['moderators'], self.env) 813 815 row['description'] = wiki_to_oneliner(row['description'], self.env) 814 816 if row['lastreply']: 815 row['lastreply'] = pretty_timedelta( row['lastreply'])817 row['lastreply'] = pretty_timedelta(float(row['lastreply'])) 816 818 else: 817 819 row['lastreply'] = 'No replies' 818 820 if row['lasttopic']: 819 row['lasttopic'] = pretty_timedelta(row['lasttopic']) 821 self.log.debug('lasttopic: %s' % row['lasttopic']) 822 row['lasttopic'] = pretty_timedelta(float(row['lasttopic'])) 820 823 else: 821 824 row['lasttopic'] = 'No topics' 822 825 row['time'] = format_datetime(row['time']) … … 829 832 columns = ('id', 'forum', 'time', 'subject', 'body', 'author', 830 833 'replies', 'lastreply') 831 834 sql = "SELECT t.id, t.forum, t.time, t.subject, t.body, t.author," \ 832 " (SELECT COUNT(m.id) FROM message m, topic t WHERE m.topic = t.id)" \833 " AS replies, (SELECT MAX(m.time) FROM message m, topic t WHERE" \834 " m.topic = t.id) AS lastreply FROM topic t WHERE t.forum = %s" \835 " ORDER BY "+ order_by + (" ASC", " DESC")[bool(desc)]835 " m.replies, m.lastreply FROM topic t LEFT JOIN (SELECT COUNT(id)" \ 836 " AS replies, MAX(time) as lastreply, topic FROM message GROUP BY" \ 837 " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \ 838 + order_by + (" ASC", " DESC")[bool(desc)] 836 839 self.log.debug(sql % (forum,)) 837 840 cursor.execute(sql, (forum,)) 838 841 topics = [] … … 841 844 row['author'] = wiki_to_oneliner(row['author'], self.env) 842 845 row['body'] = wiki_to_html(row['body'], self.env, req) 843 846 if row['lastreply']: 844 row['lastreply'] = pretty_timedelta( row['lastreply'])847 row['lastreply'] = pretty_timedelta(float(row['lastreply'])) 845 848 else: 846 849 row['lastreply'] = 'No replies' 847 850 row['time'] = format_datetime(row['time']) -
0.10/tracdiscussion/wiki.py
old new 136 136 id), title = label, class_ = 'missing') 137 137 elif ns == 'topic': 138 138 columns = ('forum', 'forum_subject', 'subject') 139 sql = "SELECT t.forum, (SELECT f.subject FROM forum f, topic t" \ 140 " WHERE f.id = t.forum), t.subject FROM topic t WHERE t.id = %s" 139 sql = "SELECT t.forum, f.subject, t.subject FROM topic t LEFT" \ 140 " JOIN (SELECT subject, id FROM forum GROUP BY id) f ON" \ 141 " t.forum = f.id WHERE t.id = %s" 141 142 self.log.debug(sql % (id,)) 142 143 cursor.execute(sql, (id,)) 143 144 for row in cursor: … … 149 150 id), title = label, class_ = 'missing') 150 151 elif ns == 'message': 151 152 columns = ('forum', 'topic', 'forum_subject', 'subject') 152 sql = "SELECT m.forum, m.topic, (SELECT f.subject FROM forum f," \153 " message m WHERE f.id = m.forum), (SELECT t.subject FROM" \154 " topic t, message m WHERE t.id = m.topic) FROM message m" \155 " WHEREm.id = %s"153 sql = "SELECT m.forum, m.topic, f.subject, t.subject FROM" \ 154 " message m, (SELECT subject, id FROM forum GROUP BY id) f," \ 155 " (SELECT subject, id FROM topic GROUP BY id) t WHERE" \ 156 " m.forum = f.id AND m.topic = t.id AND m.id = %s" 156 157 self.log.debug(sql % (id,)) 157 158 cursor.execute(sql, (id,)) 158 159 for row in cursor: -
0.10/tracdiscussion/search.py
old new 43 43 44 44 # Search in messages 45 45 columns = ('id', 'forum', 'topic', 'time', 'author', 'body', 'subject') 46 sql = "SELECT id, forum, topic, time, author, body, (SELECT" \ 47 " subject FROM topic t WHERE t.id = message.topic) FROM message" \ 48 " WHERE body LIKE '%%%s%%'" % (query) 46 sql = "SELECT m.id, m.forum, m.topic, m.time, m.author, m.body," \ 47 " t.subject FROM message m LEFT JOIN (SELECT subject, id FROM" \ 48 " topic GROUP BY id) t ON t.id = m.topic WHERE body LIKE '%%%s%%'" \ 49 % (query) 49 50 self.log.debug(sql) 50 51 cursor.execute(sql) 51 52 for row in cursor: -
0.10/tracdiscussion/timeline.py
old new 96 96 97 97 def _get_changed_topics(self, cursor, start, stop): 98 98 columns = ('id', 'subject', 'author', 'time', 'forum', 'forum_name') 99 sql = "SELECT t.id, t.subject, t.author, t.time, t.forum, (SELECT" \100 " f.name FROM forum f, topic t WHERE f.id = t.forum) FROM topic t" \101 " WHERE t.time BETWEEN %s AND %s"99 sql = "SELECT t.id, t.subject, t.author, t.time, t.forum, f.name" \ 100 " FROM topic t LEFT JOIN (SELECT name, id FROM forum GROUP BY id)" \ 101 " f ON t.forum = f.id WHERE time BETWEEN %s AND %s" 102 102 self.log.debug(sql % (start, stop)) 103 103 cursor.execute(sql, (start, stop)) 104 104 for row in cursor: … … 108 108 def _get_changed_messages(self, cursor, start, stop): 109 109 columns = ('id', 'author', 'time', 'forum', 'topic', 'forum_name', 110 110 'topic_subject') 111 sql = "SELECT m.id, m.author, m.time, m.forum, m.topic, (SELECT" \112 " f.name FROM forum f, message m WHERE f.id = m.forum), (SELECT" \113 " t.subject FROM topic t, message m WHERE t.id = m.topic) FROM" \114 " message m WHERE m.time BETWEEN %s AND %s"111 sql = "SELECT m.id, m.author, m.time, m.forum, m.topic, f.name," \ 112 " t.subject FROM message m, (SELECT name, id FROM forum GROUP BY" \ 113 " id) f, (SELECT subject, id FROM topic GROUP BY id) t WHERE" \ 114 " t.id = m.topic AND f.id = m.forum AND time BETWEEN %s AND %s" 115 115 self.log.debug(sql % (start, stop)) 116 116 cursor.execute(sql, (start, stop)) 117 117 for row in cursor:
