Hi,

I get the following error message when a user saves a node of a special content type and when any user wants to see any node of this specific content type: and it seems to me that it has to do with Content Access:

user warning: Unknown column 'n.nid' in 'on clause' query: SELECT name FROM users 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 = 34 AND na.realm = 'content_access_author') OR (na.gid = 2 AND na.realm = 'content_access_rid') OR (na.gid = 8 AND na.realm = 'content_access_rid') OR (na.gid = 12 AND na.realm = 'content_access_rid'))) AND ( uid = '34') in /srv/www/vhosts/meineseite.de/httpdocs/sites/all/themes/meintemplate/template.php on line 129.

I added a function to my template.php in order to get the user-id in a view - I use this function in some views:

127 function getUserName($id) {
128   $sql = "SELECT name FROM {users} WHERE uid = '$id'";
129   $result = db_query(db_rewrite_sql($sql));
130   $username = db_fetch_object($result);
131   return $username->name;
132 }

This just because of the last sentence in the error message.

My question: I have not that high programming skills to understand exactly what the error message want to tell me. Is there any confusion between content access and this function because of line 129???? Can anyone help me please????

Greez,
Tobias

Comments

P.Smith’s picture

Title: Error message » Unknown column 'n.nid'

Hello,

In the sql that content access adds I added in "drupal_node as n" and this resolved the issue. Albeit I did this through the module it was adding sql code for. Sadly, I don't know where to change this in content access. Not enough time to look through the code right now.

So your own query would become:

SELECT name FROM users JOIN node n 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 = 34 AND na.realm = 'content_access_author') OR (na.gid = 2 AND na.realm = 'content_access_rid') OR (na.gid = 8 AND na.realm = 'content_access_rid') OR (na.gid = 12 AND na.realm = 'content_access_rid'))) AND ( uid = '34')

But you would need this changing as uid exists in more than one table the code is querying. (I'm guessing the uid should refer to users.uid?)

fago’s picture

Category: bug » support
Status: Active » Fixed

You use db_rewrite_sql() wrong, this is the cause for the error. Read it's API docs.

Status: Fixed » Closed (fixed)

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

El Bandito’s picture

Fago

I've got exactly the same issue as #1 and have read the suggested API doc. Unfortunately I still don't understand why my code thus :

  $sql = "SELECT c.nid FROM {content_field_contract_template_ref} c WHERE c.field_contract_template_ref_nid = %d";
  $result = db_query(db_rewrite_sql($sql), $template_node->nid);

is incorrect. A quick pointer would be very helpful.

Thanks

El Bandito’s picture

For any future newbies I resolved this with :

$result = db_query(db_rewrite_sql($sql,'content_field_contract_template_ref'), $template_node->nid);

although my sql skills don't yet extend to a deep understanding how this works !