Invalid SQL request
yakuza-fs - November 27, 2008 - 00:17
| Project: | Taxonomy VTN |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | AlexisWilke |
| Status: | closed |
Jump to:
Description
When option "Where we go on click a term" is set to "taxonomy/term/xxx" Taxonomy VTN shows incorrect counters for every term. I've checked the code and found that you use
$tcount = taxonomy_term_count_nodes($term->tid);for other options, like "taxonomy/term/xxx/all" and "node list" but for the mentioned option above you use
$tcount = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid));which is absolutely incorrect. IMHO this request return the amount of all nodes in the specified term but all nodes revisions also! Therefore, my counts show me that I have 20 nodes for this term but there is just one node in real with tons of revisions.
It should be something like...
$tcount = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d GROUP BY vid", $term->tid));I am wondering if there is a Drupal API function to count nodes in a single term (without child terms) as using direct SQL requests isn't a good practice.
Thanks for module. I am still playing with it... I am probably going to use it if there will not be more serious bugs :)
Take care

#1
Forgot to put integer definition as it doesn't shows zeros without it in place. So the replacement string looks like
$tcount = (int)db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d GROUP BY vid", $term->tid));#2
I am sorry guys. My SQL request isn't valid as well. I am looking into it now. Will update you. For now please ignore my code patches.
Cheers.
#3
That's it! The solution is here:
$tcount = (int)db_result(db_query("SELECT COUNT({term_node}.nid) FROM {term_node} JOIN {node} ON {term_node}.vid = {node}.vid WHERE {term_node}.tid = %d", $term->tid));This request joins two tables to make sure we count only latest (current) revisions. You are welcome :)
#4
hello,
i have no time latest but will be good if you write a line number where is a problem.
I must look for this, not remember that someone tell about this problem....
anyway thanks.
#5
Line number is 245. File: taxonomy_vtn.pages.inc
People probably do not use "taxonomy/term/xxx" for "Where do we go on a term click"... You may test it by yourself, just switch to "taxonomy/term/xxx" and check counts near by the terms in the terms list.
#6
Hi yakuza-fs,
You were right, the count was wrong. With the old code and your code it gets out wrong. That is, your code was close, but you did not check whether nodes were currently published.
I wrote the fix and checked it in. It will be available soon in 6.x-1.x-dev.
The correct functions call needs to include the related terms, not the children. That's where the problem was.
You can see the function I now use to count in the taxonomy_vtn_overwrites.inc.php
Thank you.
Alexis Wilke
--project followup subject--
Automatically closed -- issue fixed for two weeks with no activity.
#7
Automatically closed -- issue fixed for two weeks with no activity.