SQL Error in Week.module

jw867 - June 29, 2006 - 03:18
Project:Weekly Archive by Node Type
Version:4.7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Prometheus6
Status:closed
Description

I upgraded to 4.7, php5 and mysql5, and I've been getting these errors:

Unknown column 'node.nid' in 'on clause' query: SELECT YEARWEEK(FROM_UNIXTIME(changed),0) AS weekno FROM node n INNER JOIN node_access na ON na.nid = node.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 1 AND na.realm = 'node_privacy_byrole_role') OR (na.gid = 0 AND na.realm = 'node_privacy_byrole_user'))) AND n.type IN ('image','page','poll','story') GROUP BY weekno ORDER BY weekno DESC LIMIT 11 in /var/www/therailfan/includes/database.mysql.inc on line 120.

There might be a similar discussion of the problem here: http://drupal.org/node/40763

Any thoughts? Thanks!

#1

Prometheus6 - June 30, 2006 - 02:20
Assigned to:Anonymous» Prometheus6
Status:active» fixed

Well, this case wasn't quite that hairy but I believe I abused db_rewrite_sql() too.

The change was just committed. For folks that want to edit by hand, find the _weekly_contentQuery() function and replace this

<?php
 
// create the SQL for the query
 
$query_info[0] = db_rewrite_sql('SELECT n.nid FROM {node} n WHERE (n.created >= '.$start_date.') and (n.created <= '.$end_date.') AND (n.status = 1) ');
 
$query_info[0] .= count($nodes_to_include) > 0 ? 'AND n.type IN (' . implode(',', $nodes_to_include) . ') ': '';
 
$query_info[0] .= 'ORDER BY n.created '. ($_week_config['week_rev_pagesort'] ? 'ASC' : 'DESC');
 
$query_info[1] = $start_date;
 
$query_info[2] = $end_date;
 
$query_info[3] = db_rewrite_sql('SELECT COUNT(n.nid) FROM {node} n WHERE (n.created >= '.$start_date.') AND (n.created <= '.$end_date.') AND (n.status = 1) ');
 
$query_info[3] .= count($nodes_to_include) > 0 ? 'AND n.type IN (' . implode(',', $nodes_to_include) . ') ': '';
?>

with this
<?php
  $query_info
[0] = 'SELECT n.nid FROM {node} n WHERE (n.created >= '.$start_date.') and (n.created <= '.$end_date.') AND (n.status = 1) ';
 
$query_info[0] .= count($nodes_to_include) > 0 ? 'AND n.type IN (' . implode(',', $nodes_to_include) . ') ': '';
 
$query_info[0] .= 'ORDER BY n.created '. ($_week_config['week_rev_pagesort'] ? 'ASC' : 'DESC');
 
$query_info[0] = db_rewrite_sql($query_info[0], 'n', 'nid');
 
$query_info[1] = $start_date;
 
$query_info[2] = $end_date;
 
$query_info[3] = 'SELECT COUNT(n.nid) FROM {node} n WHERE (n.created >= '.$start_date.') AND (n.created <= '.$end_date.') AND (n.status = 1) ';
 
$query_info[3] .= count($nodes_to_include) > 0 ? 'AND n.type IN (' . implode(',', $nodes_to_include) . ') ': '';
 
$query_info[3] = db_rewrite_sql($query_info[3], 'n', 'nid');
?>

AttachmentSize
WEEK_REWRITESQL.patch 1.37 KB

#2

Prometheus6 - July 1, 2006 - 12:15
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.