Hi,

I've just released a new site which has nodes only accessible by authenticated users. These nodes also have attached files via upload.module. I struck a problem where users were unable to download these files due to a bug in upload.module, instead they received 'page not found', with the following error output:

user error: Unknown table 'na' in where clause
query: SELECT DISTINCT(f.nid), f.* from cms_files f WHERE (na.grant_view = 1 AND CONCAT(na.realm, na.gid) IN ('all0','term_access2','term_access6')) AND filepath = 'files/20050307_minutes.doc' in /srv/www/htdocs/docs_renegades/www/includes/database.mysql.inc on line 66.

The problem was that the node_db_rewrite_sql() WHERE statement was being inserted, but not the corresponding JOIN statement (where 'na' is declared as an alias of {node_access}).

Looking through the code it seems this is because the regex in the db_rewrite_sql() function is looking for 'FROM' (all caps), whereas the upload.module query sent to db_rewrite_sql has 'from' (lower case). Changing from -> FROM fixes the problem.

This patch should apply to 4.6.0 and cvs, though I didn't look to see if the cvs version of db_rewrite_sql() still looks for an uppercase FROM.

Cheers,
Eric

CommentFileSizeAuthor
upload.module.from_FROM.patch910 bytesejort

Comments

ec’s picture

You folk, you save my day. I found this bug yesterday while I was using OG see here http://drupal.org/node/22664. I test your patch and it solves my problem, many many thanks. Hope this will be committed soon. I will also post to OG. Regards, Eric

dries’s picture

Committed to HEAD and DRUPAL-4-6.

Anonymous’s picture