See http://drupal.org/node/144840

I searched all Drupal modules and this module was the only one that appeared to flag up the potential for the reported bug. The attached patched is not fully tested but it does pass php -l liny tests (no syntax errors). Read the above issue and check out the patch.

Comments

darren oh’s picture

Version: master » 5.x-1.x-dev
StatusFileSize
new4.56 KB

Here's a patch for the 5.x version. I couldn't think of a reason to add table aliases where we're not using db_rewrite_sql(), so I didn't. Please let me know if it solves the problem.

darren oh’s picture

Status: Needs review » Fixed

I don't get any errors, so I'm committing without review. Fixed in CVS commit 83790.

basby’s picture

Title: make all queries db_rewrite_sql() safe » Change to patch - then it works
Version: 5.x-1.x-dev » 5.x-1.10

Thanks for the patch. I have installed it on my system (drupal 5.2, gsitemap-5.x-1.10) because I received the following error when submitting a post to the forum, a story or whatever:

user warning: Unknown column 'term_data.tid' in 'on clause' query: SELECT COUNT(*) FROM xxxterm_data td LEFT JOIN xxxforum_access fa ON term_data.tid = fa.tid LEFT JOIN xxxacl acl ON acl.name = term_data.tid AND acl.module = 'forum_access' LEFT JOIN xxxacl_user aclu ON aclu.acl_id = acl.acl_id AND aclu.uid = 0 WHERE ((fa.grant_view >= 1 AND fa.rid IN (1)) OR fa.tid IS NULL OR aclu.uid = 0) in

Installing the patch did not solve the problem. I had to change something more (additional to the patch). I changed all occurrences of 'term_data' to 'td' EXCEPT for one:

$output .= _gsitemap_sublinks($additional, 'term_data', 'tid', $range, $previous_links);

So do not change anything in this line!

The results of applying the patch and my changes is shown in the following line (this is only 1 of many lines that is changed):

Original line:
$count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {term_data}', 'term_data', 'tid')));

After applying the patch:
$count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {term_data} td', 'term_data', 'tid')));

After applying my changes:
$count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {term_data} td', 'td', 'tid')));

The result of my changes was that the warning disappeared and the problem is solved.

AjK’s picture

Title: Change to patch - then it works » make all queries db_rewrite_sql() safe

Please don't change descriptive titles to something totally non-descript

darren oh’s picture

It turns out that this whole issue exists because the primary table name needs to be in curly braces (not documented). I went with aliases because it's cleaner. Fixed in CVS commit 84038.

Anonymous’s picture

Status: Fixed » Closed (fixed)