SQL Error: Unknown column 'n.nid'

kahenya - September 4, 2008 - 12:43
Project:Nodecarousel
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

OK. This Error has probably been reported but I could not find it. Anyway I have a problem. When the carousel runs as admin, the error message before does not appear. As an ordinary user, the error message appears below. I disabled gmaps, and the error was there. I'm a bit lost. Any solutions?

user warning: Unknown column 'n.nid' in 'on clause' query: SELECT count(node.nid) FROM node node LEFT JOIN gmap_latlon gmap_latlon_field_location_0 ON node.vid = gmap_latlon_field_location_0.vid AND gmap_latlon_field_location_0.field_name = 'field_location_0' INNER JOIN node_access na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all'))) AND ( (node.type IN ('event')) ) in /***/***/htdocs/includes/database.mysql.inc on line 172.

Thanks.

Kahenya

#1

Dave Reid - September 4, 2008 - 13:26

Looks like it should be node.nid. The node table isn't given the 'n' table alias.

#2

Dave Reid - September 4, 2008 - 13:26
Title:MySQL Not???» SQL Error: Unknown column 'n.nid'

#3

Summit - September 4, 2008 - 14:45

Hi,
I do not think is should be node.nid.
I think this is causing by a mistake of the query as: http://drupal.org/node/51696
It happens when you have access module inserting in the module query is my investigation.
I myself have still also errors like this after going for domain access.

So you have to find the query and rewrite it as described in attached link, I think.

greetings,
Martijn

#4

Kevin Hankens - September 4, 2008 - 14:55

Actually, I would agree with Dave Reid.

This code:SELECT count(node.nid) FROM node node...

Queries the table "node" and gives it an alias of "node". But, INNER JOIN node_access na ON na.nid = n.nid is trying to do a join on table (or alias) "n", which hasn't been defined.

Try changing the JOIN statement to INNER JOIN node_access na ON na.nid = node.nid

Good luck!

#5

jcfiala - September 4, 2008 - 15:14
Status:active» won't fix

I don't have any references to gmap code in nodecarousel, so this is most likely a SQL query that you or some other part of the code is constructing, not the nodecarousel. I suggest doing a search for this query and correctin git.

#6

Summit - September 4, 2008 - 15:23

problem is, as I tried to describe that probably the

INNER JOIN node_access na ON na.nid = n.nid

is from the access usage, I do not think altering this is the way to go.

greetings,
Martijn

#7

Dave Reid - September 4, 2008 - 15:31
Project:Nodecarousel» GMap Lat/Lon
Version:5.x-1.x-dev» 5.x-0.1
Status:won't fix» active

The only module I can find with the gmap_latlon table is (duh) the GMap Lat/Lon module. Moving this issue to that module's issue queue.

#8

kahenya - September 7, 2008 - 08:58
Project:GMap Lat/Lon» Nodecarousel
Version:5.x-0.1» 5.x-1.x-dev

Returning to Nodecarousel

Hi,

Sorry away 2 days for Off line Forum

Even with all the other modules disabled. I still get the error below

user warning: Unknown column 'n.nid' in 'on clause' query: SELECT count(node.nid) FROM node node INNER JOIN node_access na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all'))) AND ( (node.type IN ('event')) ) in /***/***/***/includes/database.mysql.inc on line 172.

I have even removed the modules, run nodecarousel on a sterile Drupal with the bare minimums and get the same error. I have tried a lot of the above options, none work.

Any other ideas?

Thanks,

Kahenya

#9

Summit - September 7, 2008 - 10:25

Hi,
Just quick, I do not have a lot of time.
Are you aware that the

On na.nid = n.nid Where (na.grant_view.... etc..

Is added to you query through your access rules. With db_rewrite_sql statement you add this to your query.
there are lots of problems with this access rule additing and already available queries in all sorts of modules.
The best solution I saw, is that you first and for all make the n.nid field the first in the SELECT query.

Please search drupal.org on db_rewrite_sql and node access and you will find lots of forum posts about this subject.
Sometimes just not using db_rewrite_sql helps, but be aware that the query is not following access rules anymore if you need those!

greetings,
Martijn

#10

kahenya - September 8, 2008 - 09:44

Well

Quickie update. If you have Views 5.16, and nodecarousel dev or stable, this issue comes up. If I try run nodecarousel with any other option the error disappears. However, with views it appears.

Where to to look next and what to look for?

Kahenya

#11

kahenya - September 23, 2008 - 20:22
Status:active» closed

Resolved

#12

kenorb - January 16, 2009 - 00:45
Status:closed» duplicate

Duplicate of #331651: db_rewrite_sql improperly rewriting a subquery

 
 

Drupal is a registered trademark of Dries Buytaert.