Changeset 86

Show
Ignore:
Timestamp:
03/25/08 01:07:05 (8 months ago)
Author:
brad
Message:

more tablename separation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tracforums/db.py

    r85 r86  
    44 
    55class TablenamesImpl(dict): 
    6     avatar = "avatar" 
    7     category = "forum_category" 
    8     forum = "forum" 
    9     message = "message" 
    10     moderator = "moderators" 
    11     profile = "profile" 
    12     project = "project" 
    13     topic = "topic" 
    14     touchedtopic = "touched_topic" 
    15     forumwatch = "forum_watch" 
    16     topicwatch = "topic_watch" 
    17     projectwatch = "project_watch" 
    186     
    197    # allow the above members to look like dict key/value pairs 
    20     def __init__(self): 
    21         dict.__init__(self,self.__class__.__dict__) 
     8    def __init__(self, prefix=""): 
     9 
     10        tables = { 
     11            "avatar"       : "avatar", 
     12            "category"     : "forum_category", 
     13            "forum"        : "forum", 
     14            "message"      : "message", 
     15            "moderator"    : "moderators", 
     16            "profile"      : "profile", 
     17            "project"      : "project", 
     18            "topic"        : "topic", 
     19            "touchedtopic" : "touched_topic", 
     20            "forumwatch"   : "forum_watch", 
     21            "topicwatch"   : "topic_watch", 
     22            "projectwatch" : "project_watch" 
     23        } 
     24         
     25        for k,v in tables.iteritems(): 
     26            tables[k] = prefix + v 
     27 
     28        dict.__init__(self,tables) 
     29        self.__dict__ = self 
    2230 
    2331# Singleton for table name data 
  • trunk/tracforums/models/forum.py

    r85 r86  
    2727                 
    2828        # aliases 
    29         "forumid":     ORMAlias(sql="forum.id"), 
    30         "topicCount":  ORMAlias(sql="coalesce((select count(id) from %(topic)s as t where forum.id = t.forumid),0)" % Tablenames), 
    31         "viewCount":   ORMAlias(sql="coalesce((select sum(views) from %(topic)s as t where t.forumid=forum.id),0)" % Tablenames), 
     29        "forumid":     ORMAlias(sql="%(forum)s.id" % Tablenames), 
     30        "topicCount":  ORMAlias(sql="coalesce((select count(id) from %(topic)s as t where %(forum)s.id = t.forumid),0)" % Tablenames), 
     31        "viewCount":   ORMAlias(sql="coalesce((select sum(views) from %(topic)s as t where t.forumid=%(forum)s.id),0)" % Tablenames), 
    3232        "replyCount":  ORMAlias(sql=""" 
    3333            coalesce( 
     
    3535                    from %(topic)s as t join %(message)s as m on m.topicid = t.id  
    3636                    where t.forumid = %(forum)s.id 
    37                 ) - (select count(id) from %(topic)s as t where t.forumid=forum.id) 
     37                ) - (select count(id) from %(topic)s as t where t.forumid=%(forum)s.id) 
    3838            ),0) 
    3939        """ % Tablenames), 
  • trunk/tracforums/models/topic.py

    r85 r86  
    3030        # synthetic columns 
    3131        "viewCount":     ORMAlias(sql=""" 
    32             coalesce((select sum(views) from %(topic)s as t where t.id=topic.id),0) 
     32            coalesce((select sum(views) from %(topic)s as t where t.id=%(topic)s.id),0) 
    3333        """ % Tablenames), 
    3434         
     
    3737                (select (select count(m.id) 
    3838                    from %(message)s as m 
    39                     where m.topicid = topic.id 
     39                    where m.topicid = %(topic)s.id 
    4040                ) - 1 
    4141            ),0) 
     
    4646                select max(m.id) 
    4747                from %(message)s as m 
    48                 where m.topicid = topic.id 
     48                where m.topicid = %(topic)s.id 
    4949            ) 
    5050        """ % Tablenames),