posting this as a separate issue to from: http://drupal.org/node/69111

I just discovered there is a minor problem with the code committed to 5.x/HEAD that generates the comment list for the recent comment block:

This query:

  $result = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node_comment_statistics} n WHERE n.comment_count > 0 ORDER BY n.last_comment_timestamp DESC"), 0, $number);

Actually should (I think) be written something like:

  $result = db_query_range(db_rewrite_sql("SELECT nc.nid FROM {node_comment_statistics} nc WHERE nc.comment_count > 0 ORDER BY nc.last_comment_timestamp DESC", 'nc'), 0, $number);

to conform to the API for db_rewrite_sql. Otherwise, this causes SQL errors in modules that implement hook_db_rewrite_sql: http://drupal.org/node/111421

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pwolanin’s picture

Status: Active » Needs review
FileSize
1.01 KB

Patch attached as per above. Seems to fix the rewrite SQL problem, at least with modr8.module

pwolanin’s picture

Priority: Normal » Critical

this breaks the block, but the fix is obvious.

Alos, should the alias for the table be 'nc' or 'cs' or 'ncs'? Elsewhere in core 'c' alone is used, but this seems foolish and confusing, since this is the alias used for the comments table. I'll happily write a patch next to fix all those.

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Code looks okay to me.

Dries’s picture

Odd. I wonder why this query fails. Is 'n' a reserved keyword for the query rewriter?

pwolanin’s picture

@Dries- As I understand the problem, "n" is accepted as the standard alias for {node}, so implementations of hook_db_rewrite_sql can try to join against fields in {node} if the table alias "n" is passed in. If one is selecting form a different table, then the rewrite code has to left join to the {node} table in order to test on fields there.

See this example code: http://api.drupal.org/api/HEAD/function/hook_db_rewrite_sql

pwolanin’s picture

FileSize
1004 bytes

attached patch updated for HEAD (though comment module is so badly broken in general that I can't re-test it)

ChrisKennedy’s picture

The patch to fix comments in HEAD is at http://drupal.org/node/124742 fyi.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Alright! Got it now. I've committed to CVS HEAD and DRUPAL-5. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
Marc Bijl’s picture

Category: bug » support
Priority: Critical » Normal
Status: Closed (fixed) » Fixed

Hi,

Not sure if my follow up here is the way to go, but after upgrading from Drupal 5.1 to 5.2 I've found that the change of code in the comment module causes a wrong internationalized comment block (using i18n-5.x-2.1). Probably i18n needs to be corrected, so therefore I've reported this bug:
- http://drupal.org/node/166189

But may be it has something to do with the comment module - I don't know.

Cheers,
Marc

Anonymous’s picture

Status: Fixed » Closed (fixed)