Hi,

Anonymous visitors get SQL error when viewing any URL in the site:


user warning: Unknown table 'n' in on clause query: SELECT node.title, node.nid, node.changed FROM node INNER JOIN term_node ON node.nid = term_node.nid INNER JOIN node_access na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 1 AND na.realm = 'content_access_rid'))) AND ( term_node.tid = 1 AND node.status = 1 AND node.moderate = 0 AND node.promote = 1 ) ORDER BY node.created DESC LIMIT 5 in /srv/squared/www/newsite.squaredesign.nl/includes/database.mysql.inc on line 172

I tested in two environments with identical Drupal setup.
ACL module is not used.

Comments

keesje’s picture

Would someone edit my post, and remove the explicit file path in the message?

Thanks.

Kees

keesje’s picture

There seems to be a lot goin on with "Unknown table 'n' " regarding Drupal modules. So much posts and treads, I can't see a solution.

keesje’s picture

Saving the access control tab from a content type, results in this errormessage:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM node n WHERE type = 'page'' at line 1 query: SELECT .nid FROM node n WHERE type = 'page' in C:\wamp\www\square\includes\database.mysql.inc on line 172.

keesje’s picture

Priority: Normal » Critical

It get's worse,
even disabling, end un-installing the module does not help. The only things I changed, was installing this module, and the core 'upload' module. I did this two times, on different servers, with same result.

Even stranger: nodes added after uninstalling the module, is causing them to be not alowed from view by anonymous users. The old nodes are, all URL's are showing the SQL error.

Quick conclusion:
content access is changing Drupal's default per-node access settings?

Does this sound familiar to anyone?

keesje’s picture

More info:

node_access table gets altered. When restoring default value,
INSERT INTO `node_access` VALUES (0, 0, 'all', 1, 0, 0)
sql error disappears. when adding this line to altered table, access restrictions don't work anymore. I can understand this. I cannot understand what's happening causing the error message, but I guess this info must be close to the problem cause.

keesje’s picture

Category: bug » support
Priority: Critical » Normal

Reading through all the related content on this matter, it occurs to me that this could be caused by some other module, or code containing SQL statements. Changing to support request.

fago’s picture

Status: Active » Fixed

yep, this is a problem with queries that doesn't alias the node table to 'n' but use db_rewrite_sql, then the query fails when a node access module is used.

AndrewJarvis’s picture

So... what do we do? I'm having the same problem

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN node_access na ON na.nid = node.nid WHERE (na.grant_view >= 1 AND ((n' at line 1 query: INNER JOIN node_access na ON na.nid = node.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all'))) LIMIT 0, 5 in /home/content/l/i/q/liquidmethods/html/clovenhandv4/includes/database.mysql.inc on line 172.

AndrewJarvis’s picture

Oh, and by the way - I never used the Content Access module

keesje’s picture

In my case, I used a PHP snippet from someone else:
http://drupal.org/node/58861

It tricked me on the "db_rewrite_sql" part, only in combination with some access control enhancement module.

I just removed the "db_rewrite_sql" statement, because access control is not relevant in this case.

Looking at your SQL message, it could be that you used the same code snippet...

Anyway, this discussion is out of place in this issue queue. Please move to forum if you want to discuss further.

Luck,

Kees

Anonymous’s picture

Status: Fixed » Closed (fixed)
oddible’s picture

Not sure why this was closed. Content Access is adding its INNER JOIN clause in the wrong place, it is getting attached to a clause that doesn't have the node table referenced. I see similar issues posted that are not the same as this, I am surprised to see that this one got sidetracked by bad analysis. Content Access consistently has problems if a View is built on a compound query.