After installing filter_by_taxo, I placed a side block and this is the message I got:

user warning: Unknown table 'n' in on clause query: SELECT DISTINCT tn.tid FROM term_node tn INNER JOIN term_data td ON td.tid = tn.tid LEFT JOIN localizernode loc ON loc.nid=n.nid WHERE (loc.locale IN ('es','-') OR loc.locale IS NULL) AND ( NOT (tn.tid IN (5) ) AND (tn.nid IN (24)) AND (td.vid = 5)) in (suppressed)/drupal-5.0/includes/database.mysql.inc on line 167.

I see there is a

n.nid

that shoule be

tn.nid

I understand it must be an error from refine by taxo, although I see lots of localizer references in the text, might it be another module's bug? I get no error if I remove refinement blocks.

CommentFileSizeAuthor
#12 refine_by_taxo_0.patch644 bytesrobertgarrigos

Comments

Bèr Kessels’s picture

Project: Refine by taxonomy » Localizer
Priority: Critical » Normal

The part 'LEFT JOIN localizernode loc ON loc.nid=n.nid WHERE' comes from another module, one I don't know about frankly. That is the module creating the wrong SQL, so I am re-assigning this, and will be following along with the conversation within that projet.

bès’s picture

Version: 5.x-1.x-dev » 5.x-1.7

I got the same bug when i use the admin account.
It disappears when i deactivate the Localizer node module.

I try with a normal user and i got a similar error :

user warning: Unknown column 'n.nid' in 'on clause' query:
SELECT DISTINCT tn.tid
FROM d5_term_node tn
INNER JOIN d5_term_data td ON td.tid = tn.tid
INNER JOIN d5_node_access na ON na.nid = n.nid
WHERE (na.grant_view >= 1
AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 2 AND na.realm = 'term_access') OR (na.gid = 9 AND na.realm = 'term_access') OR (na.gid = 11 AND na.realm = 'term_access')))
AND ( NOT (tn.tid IN (1) )
AND (tn.nid IN (17,16,15))
AND (td.vid = 1))
in [...]drupal-5.1/includes/database.mysql.inc on line 172.

INNER JOIN d5_node_access na ON na.nid = n.nid
should be
INNER JOIN d5_node_access na ON na.nid = tn.nid ?

this time the error comes from node module...
File node.module, function _node_access_join_sql()

Roberto Gerola’s picture

What module are you using ?
It seems to me that this module use the call db_rewrite_sql method, but doesn't pass the correct
primary table. If no primary table is specified the default is n, i.e., node.
The primary table that it should pass should be 'tn' instead.

bès’s picture

In my case, I got the both bug after installing the 'Refine by taxonomy' module.

As i got the bug with two different module (node and localizernode), I also think that the problem comes from passing argument.

Roberto Gerola’s picture

Assigned: Unassigned » Roberto Gerola
Category: bug » support
Status: Active » Fixed

In refine_by_taxo.module :
$sql = db_escape_string('SELECT DISTINCT tn.tid FROM {term_node} tn INNER JOIN {term_data} td ON td.tid = tn.tid WHERE' . $conditions);
$result = db_query(db_rewrite_sql($sql));

The use of db_rewrite_sql is not correct, it should be : db_rewrite_sql($sql, 'tn', tid)
The parameters are explained here : http://api.drupal.org/api/HEAD/function/db_rewrite_sql

Farreres’s picture

Sorry, roberto. Do you mean this is a refine_by_taxo bug? Could you then move this bug to this other module so they know it?

Roberto Gerola’s picture

Project: Localizer » Refine by taxonomy
Version: 5.x-1.7 » 5.x-1.x-dev
Category: support » bug

In refine_by_taxo.module :

191: $sql = db_escape_string('SELECT DISTINCT tn.tid FROM {term_node} tn INNER JOIN {term_data} td ON td.tid = tn.tid WHERE' . $conditions);
192 : $result = db_query(db_rewrite_sql($sql));

The use of db_rewrite_sql function is not correct, it should be : db_rewrite_sql($sql, 'tn', 'tid')
Please, correct this, otherwise other modules cannot work correctly.

The parameters are explained here : http://api.drupal.org/api/HEAD/function/db_rewrite_sql

Roberto Gerola’s picture

Status: Fixed » Needs review
Bèr Kessels’s picture

assigning to myself.

Farreres’s picture

has it been finally fixed?

pacesie’s picture

Title: Wrong sql » Is a patch available?

This bug makes the module unusable for me. Is there a patch?

robertgarrigos’s picture

StatusFileSize
new644 bytes

I got rid of that error with this patch, although I'm having some other funny results.

Bèr Kessels’s picture

Status: Needs review » Needs work

"funny results": does that mean that we must wait a bit untill you find out what is wrong?

robertgarrigos’s picture

Status: Needs work » Needs review

nop, this is something realted to the other patch I posted (http://drupal.org/node/120271) which I din't know at the time I posted this one here. The funny results were due to the fact that this module was limiting the search query to the number of nodes set with the feed_default_items variable, so you might have funny results. For me this patch here is ready to commit but I would like someone else could confirm this, so changing this to 'needs review'.

blackjaw@pseudolife.com’s picture

This fixed everything on my site. Thanks guys!\
http://www.pseudolife.com

marcoBauli’s picture

Title: Is a patch available? » Localizer / i18n Warning: Unknown column 'n.nid'

Patch above worked fine here too :)

(changing title as it fixed same problem with Localizer)

JHeffner’s picture

Title: Localizer / i18n Warning: Unknown column 'n.nid' » Warning: Unknown column 'n.nid'

Patch worked as well. Though I had problems finding this bug page since it wasn't specific to Localizer. Changing title to make it easier to find since it's specific to this module.

Bèr Kessels’s picture

Status: Needs review » Reviewed & tested by the community

code looks good.

JHeffner’s picture

Can you commit this? I ran into it again as soon as I upgraded to the latest version.

Bèr Kessels’s picture

Status: Reviewed & tested by the community » Fixed

committed to 5.x dev version.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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