I get this ugly pink error when I visit my view URL. It only goes away if I delete the field 'Comment: Last Changed Time' from the view, but comes back when I add the field again.

user warning: Unknown column 'node_comment_statistics.last_comment_timestamp' in 'field list' query:

SELECT node.nid, relativity_parent_node.title AS relativity_parent_node_title, relativity_parent_node.nid AS relativity_parent_node_nid, node_data_field_status.field_status_value AS node_data_field_status_field_status_value, node.title AS node_title, node.changed AS node_changed, node_data_field_deadline.field_deadline_value AS node_data_field_deadline_field_deadline_value, GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) AS node_comment_statistics_last_changed FROM node node LEFT JOIN relativity relativity ON node.nid = relativity.nid LEFT JOIN node relativity_parent_node ON relativity.parent_nid = relativity_parent_node.nid LEFT JOIN content_type_issue_log node_data_field_status ON node.vid = node_data_field_status.vid LEFT JOIN content_type_issue_log node_data_field_deadline ON node.vid = node_data_field_deadline.vid WHERE (node.type IN ('issue_log')) ORDER BY node in /.../includes/database.mysql.inc on line 172.

Please help - I've just had my dinner and it's making me feel queasy ;)

BTW What does 'Views Data' mean anyway?

Comments

JohnG-1’s picture

error 2 : when Field-Sorting by column/field 'Comment: Last Changed Time' :

error message:

user warning: Unknown column 'node_comment_statistics.last_changed' in 'order clause' query: 

SELECT node.nid, node.title AS node_title, node.changed AS node_changed, node_comment_statistics.comment_count AS node_comment_statistics_comment_count, node_comment_statistics.last_comment_timestamp AS node_comment_statistics_last_comment_timestamp, GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) AS node_comment_statistics_last_changed FROM node node LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid ORDER BY node_comment_statistics.last_changed ASC LIMIT 0, 10 in /.../drupal/includes/database.mysql.inc on line 172.

I cannot trace which function is creating the node_comment_statistics.last_changed query.

conditions:
no error 'Comment: Last Changed Time' is added as a Sort Criteria
no error 'Comment: Last Changed Time' is added as a Field; Sortable->no; Default_Sort->none
no error 'Comment: Last Changed Time' is added as a Field; Sortable->no; Default_Sort->ascending
no error 'Comment: Last Changed Time' is added as a Field; Sortable->no; Default_Sort->descending
no error 'Comment: Last Changed Time' is added as a Field; Sortable->yes; Default_Sort->none
error !!! 'Comment: Last Changed Time' is added as a Field; Sortable->yes; Default_Sort->none; and then click on the view's 'sort_this_column' link.
error !!! 'Comment: Last Changed Time' is added as a Field; Sortable->yes; Default_Sort->ascending
error !!! 'Comment: Last Changed Time' is added as a Field; Sortable->yes; Default_Sort->descending

So the error appears only when I attempt to use the 'Comment: Last Changed Time' Table Field Sortable function ... and therefore the most likely candidate (based on the 'conditions' behaviour) seems to be 'views_handler_sort_last_changed' in views_comment.inc :

function views_handler_sort_last_changed($action, &$query, $sortinfo, $sort) {
  $query->ensure_table('node_comment_statistics');
  $query->orderby[] = 'GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) ' . $sort['sortorder'];  
}

Neither PHP nor SQL are my strong point so not surprisingly I can't see anything wrong ... for comparison the most similar function appears to be in views.module :

function views_handler_sort_date($op, &$query, $sortinfo, $sort)
...
//  $query->add_field($field, $table, $as);
//  $query->orderby[] = "$alias $sort[sortorder]";
  $query->add_orderby($table, $field, $sort['sortorder'], $as);
}

interesting that 2 methods are commented out ... looks like tweaking, in which case

view_comments.inc: $query->orderby[] = 'GREATEST(node.changed, node_comment_statistics.last_comment_timestamp) ' . $sort['sortorder']; would appear to have deprecated syntax ???

could that be the problem ?

Any help most welcome - I've spent all day looking at this and all I'm sure of is that it is a genuine bug :(

merlinofchaos’s picture

Status: Active » Fixed

This is a bug; and it was fixed in dev. It was a side effect of the code to figure out how to sort using clicksort was using the wrong variable. However, that variable happened to *usually* be right. Just not quite always.

JohnG-1’s picture

Thanks for confirmation. I'll wait for ver 1.6 ... :)

Anonymous’s picture

Status: Fixed » Closed (fixed)