While updating a module for D6, I ran into an error in my hook_db_rewrite_sql where the primary table is the comments table ('c'):
user warning: Unknown table 'c' in where clause query: SELECT COUNT(*) FROM comments...
This is because of the following in the comment_render function in comments.module:
$query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
...
$query_count = db_rewrite_sql($query_count, 'c', 'cid');
So I've attached a patch that adds the 'c' table alias to the $query_count variable.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | comment-db_rewrite_sql-fix-216504-11.patch | 1.15 KB | webchick |
| #6 | comment-db_rewrite_sql-fix-216504-6.patch | 1.15 KB | webchick |
| #4 | comment-db_rewrite_sql-fix-216504-3.patch | 1.71 KB | webchick |
| #1 | comment_render_table_alias_1.patch | 1.15 KB | mcarbone |
| comment_render_table_alias.patch | 937 bytes | mcarbone |
Comments
Comment #1
mcarbone commentedOops, I missed a spot to add the alias. New patch attached.
Comment #2
mcarbone commentedThis is a very tiny fix -- without it, hook_db_rewrite_sql cannot work with the comments table. It should be easy to review.
Comment #3
webchickCan confirm the bug, and the fix. Moving to critical, since it breaks db_rewrite_sql() for comments.
To reproduce, stick the following in your module and view a node page with some comments as a non-admin user:
First problem:
(fixed w/ mcarbone's patch)
Second problem:
fixed with this one, which includes mcarbone's patch.
Also tested recent comments block, etc. and this appears to be working. Could use a couple sets of eyes, though.
Comment #4
webchickRessin' fressin. :P
Comment #5
webchickComment #6
webchickBtw, here's one that applies to 7.x without the off-set and all the svn crap at the end. Same patch.
Comment #7
webchickComment #8
dries commentedI've committed this to CVS HEAD but it should probably go into DRUPAL-6 too.
Comment #9
mcarbone commentedRe-opening the issue to be applied to Drupal 6.
Comment #10
KingMoore commentedRTBC patch coming soon.
Comment #11
webchickHere's an updated patch that applies cleanly to 6.x.
Comment #12
realityloop commentedComment #13
KingMoore commentedRTBC for real.
Comment #14
gábor hojtsyThanks, committed to Drupal 6 too.
Comment #15
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.