Forum Home
Welcome to pyForum.org.
A message board system written in pure python using the web2py framework.
Download pyForum (v1.0.3): pyForum_1-0-3.tgz.
Anonymous Users - Change Forum Language To: Deutsch | English | Español
posts/replies/views counts always zero
By: richard
Rank: Starfleet Ensign
Postings: 17
From: Australia
Posted: Wed, 06 May, 2009 - 12:03 AM

hi,

I was testing rc3 and found that the posts/replies/views counts are always zero at pyforum/default/index/.
However the counts exist in the database and work for pyforum/default/view_forum/N.

In the controller the index function uses raw SQL while view_forum uses the DAL, and I am using Sqlite instead of mysql, so this is probably a database type problem.

I noticed your comment in the source: This is one of the few SQL queries that I still need to port to web2py's DAL, any takers?
Has any work been done on this since then? If not I could give it a go.

Richard
By: Speedbird
Rank: Starfleet Lieutenant
Postings: 61
From: Camas, Washington
Posted: Wed, 06 May, 2009 - 01:05 AM

Hi Richard,

You're most likely correct. In fact it is the only sql query that still needs to be ported to the DAL, I can almost bet that is the reason why it shows up as 0's in your test environment.

In fact, I think this is the problem:

        count(nullif(zt.parent_flag='T',0)) as parents,
count(nullif(zt.parent_flag='F',0)) as siblings,


I am not too savvy with sqlite but MySQL's "nullif" does not exist in other flavors of SQL, in fact, I should've changed it to coalesce(), just for kicks, try changing the above in default.py (Lines 38-39) to:


        count(coalesce(zt.parent_flag='T',0)) as parents,
count(coalesce(zt.parent_flag='F',0)) as siblings,


And see if it works. In any case I axpect to have a DAL version of the sql query ready for the final release, if you'd like to take on this conversion I'll make sure you're noted in the project, we will probably need to talk to Massimo regarding the entire SQL query though, as it basically generates the entire main index page with one single sql call..

Thanks for testing..

-- sb
By: richard
Rank: Starfleet Ensign
Postings: 17
From: Australia
Posted: Thu, 07 May, 2009 - 02:40 AM

hi,

Here is my progress so far:

parents_field = db.zf_topic.id.count()
siblings_field = db.zf_topic.id.count()
hits_field = db.zf_topic.hits.sum()
join = [db.zf_forum.on(db.zf_forum_category.id == db.zf_forum.cat_id),
db.zf_topic.on((db.zf_forum.id == db.zf_topic.forum_id) & (db.zf_topic.disabled_flag == 0))]
groupby = db.zf_forum.id | db.zf_forum.forum_title | db.zf_forum.forum_desc | db.zf_forum.moderation_flag | db.zf_forum.anonymous_viewaccess | db.zf_forum.add_postings_access_roles | db.zf_forum_category.id | db.zf_forum_category.cat_name | db.zf_forum_category.cat_desc | db.zf_forum_category.cat_visible_to | db.zf_forum_category.cat_sort | db.zf_forum.reply_postings_access_roles | db.zf_forum.forum_sort
orderby = db.zf_forum_category.cat_sort | db.zf_forum.forum_sort
rows = db().select(
db.zf_forum_category.id, db.zf_forum_category.cat_name, db.zf_forum_category.cat_desc, db.zf_forum_category.cat_visible_to, db.zf_forum_category.cat_sort,
db.zf_forum.id, db.zf_forum.forum_title, db.zf_forum.forum_desc, db.zf_forum.moderation_flag, db.zf_forum.anonymous_viewaccess, db.zf_forum.add_postings_access_roles, db.zf_forum.reply_postings_access_roles, db.zf_forum.forum_sort,
parents_field, siblings_field, hits_field,
left=join,
groupby=groupby,
orderby=orderby
)

for row in rows:
cat_id = row.zf_forum_category.id
cat_name = row.zf_forum_category.cat_name
cat_desc = row.zf_forum_category.cat_desc
cat_visible_to_str = row.zf_forum_category.cat_visible_to
cat_sort = row.zf_forum_category.cat_sort
forum_id = row.zf_forum.id
forum_title = row.zf_forum.forum_title
forum_desc = row.zf_forum.forum_desc
moderation_flag = row.zf_forum.moderation_flag
anonymous_viewaccess = row.zf_forum.anonymous_viewaccess
add_postings_access_roles = row.zf_forum.add_postings_access_roles
reply_postings_access_roles = row.zf_forum.reply_postings_access_roles
forum_sort = row.zf_forum.forum_sort
parents = row._extra[parents_field]
siblings = row._extra[siblings_field]
hits = row._extra[hits_field]


It works apart from the parents/siblings - I need to work out the sub query syntax.
Richard
Welcome
Username:
Password:
 
Quick Search:
System Announcements
Latest Posts