Hi there,

I just installed the modr8 module and enabled the block. I also checked the settings, but left them alone. I am getting this warning at the top of the page when visiting my site anonymously.

user warning: Unknown column 'n.moderate' in 'where clause' query: SELECT n.nid FROM node_comment_statistics n WHERE ((n.moderate != 1 OR n.uid = 0)) AND ( n.comment_count > 0 ) ORDER BY n.last_comment_timestamp DESC LIMIT 0, 10 in /home/.paws/tgettig/gettig.net/includes/database.mysql.inc on line 172.

The site is http://www.gettig.net

The functionality of the module looks to be just what I am looking for, but this warning is odd. Any pointers in the right direction are appreciated. Thanks!

CommentFileSizeAuthor
#15 query.patch461 bytesjenlampton

Comments

pwolanin’s picture

I think this is due to a bug in a query in Drupal core that has been fixed. Try updating to the latest 5.x:

http://drupal.org/drupal-5.x-dev

Anthony Gettig’s picture

Hi there,

I just unpacked a freshly downloaded archive of drupal core to my site, ran update.php as the first user, but still get the error.

I'm not the most SQL savvy dude, but I took a look at that table structure. In the node_comment_statistics table, there is no column named "moderate". Could I add this field manually? If so, what should the data type be? Should I already have that column?

pwolanin’s picture

the point is the table alias in the query, not the table structure. Did you use the link above to download Drupal?

Anthony Gettig’s picture

Aha! I should have read your direction better. I downloaded from the url you posted, installed, ran the db update script, and yep, that did it. No more error message. Thanks a ton!

pwolanin’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)
x2222’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

I'm having this exact same problem with anonymous users only. Can you be more specific as to what I need to upgrade? I have Drupal 5.1, which is almost the newest. If you're suggesting I have to upgrade to 5.2, I'm a little hesitant as this was a fantastico install and I don't want to take any chances, especially with all the modules I have, before I even launch my site. Any ideas? Thank you.

-Could I try using an older version of modr8?

x2222’s picture

Anyone have any ideas for this? Is there a supposed database upgrade script that I can run that doesn't involve upgrading my Drupal 5.1 to 5.2?

scott.mclewin’s picture

I submitted the patch to core that went in for 5.3 to fix this problem. The issue is that a db_rewrite_sql call in the core comment handling code is failing to pass the primary_table and primary_field arguments. These default to "n" and "nid" and assume that the query contains the node table, that the node table is called 'n' and that the nid field on that table is 'nid'.

But the query is for node comment stats and does not contain the node. Modules like modr8 assume that any query where the primary table is named "n" contains a node and then inject additional SQL into the query based on that assumption. Modr8 is not broken here, core is.

If you want to make a local patch open up comment.module and apply the following change (find the line with the -, change it to look like the line with the +)

-  $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);
+  $result = db_query_range(db_rewrite_sql("SELECT ncs.nid FROM {node_comment_statistics} ncs WHERE ncs.comment_count > 0 ORDER BY ncs.last_comment_timestamp DESC", 'ncs'), 0, $number);

This should do it for you.

Scott

pwolanin’s picture

Status: Postponed (maintainer needs more info) » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

2c’s picture

I have Drupal 5.10 installed and I'm getting the error:

user warning: Unknown column 'n.moderate' in 'where clause' query: SELECT count(node.nid) FROM node node LEFT JOIN content_type_property node_data_field_discount ON node.vid = node_data_field_discount.vid LEFT JOIN content_type_property node_data_field_summary ON node.vid = node_data_field_summary.vid WHERE ((n.moderate != 1)) AND ( (node.status = '1') AND (node.type IN ('property')) )

I'm using 5.x-2.4.

Could this be a Views issue?

jenlampton’s picture

Project: modr8 » Drupal core
Version: 5.x-2.2 » 5.21
Component: User interface » comment.module
Category: support » bug
Status: Closed (fixed) » Active

This same issue reappeared in later versions of Drupal core. Not sure if this is a big enough issue to get a patch in, but someone working on comment should probably be aware of it.

jenlampton’s picture

Project: Drupal core » modr8
Version: 5.21 » 5.x-2.5
Component: comment.module » Code

On second look, this appears to be a new issue. The patch to 5.3 got into core and my SQL error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN node n ON node.nid = n.nid WHERE ((n.moderate != 1)) LIMIT 0, 25' at line 1 query: LEFT JOIN node n ON node.nid = n.nid WHERE ((n.moderate != 1)) LIMIT 0, 25

seems to legitimately be coming from modr8.

I've tracked the problem down to the modr8_db_rewrite_sql function. Apparently it gets called in one instance when $query is an empty string, so the result tacks a where clause on to nothing, which of course, is invalid. My fix: find line 268 in modr8.module and replace

      if (!$access) {

with

      if (!$access && $query) {

No more error!
Jen

jenlampton’s picture

Status: Active » Needs review
StatusFileSize
new461 bytes

Patch attached.

pwolanin’s picture

hmm, weird - sounds still like maybe a core issue, but looks liek a pretty safe patch.

pwolanin’s picture

Committed this fix to Drupal 6.x (HEAD) and DRUPAL-5

pwolanin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.