Hi all,

I've only just noticed this problem, because I've been developing logged in as the superuser, but as soon as I try to view a member profile page as an authenticated or anonymous user - basically, as soon as !node_access_view_all_nodes() - I get this warning:

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, 10 in D:\muun_nobackup\classiccars\includes\database.mysqli.inc on line 151.

As you can see, somehow the "SELECT ..." is being dropped from the query. Very strange! I printed the queries as they enter the node_db_rewrite_sql() hook, and they seem fine:

SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC

SELECT n.nid, r.nid AS node_id, c.*, n.title FROM {category} c INNER JOIN {category_node} r ON c.cid = r.cid INNER JOIN {category} cn ON c.cnid = cn.cid INNER JOIN {node} n ON c.cid = n.nid INNER JOIN {node} cnn ON cn.cid = cnn.nid WHERE n.status = 1 AND r.nid = %d ORDER BY cn.weight, cnn.title, c.weight, n.title 

But when they come out the other side they're all messed up. This is frying my brain. I have no idea where to START working out how/why/where Drupal is dropping the fed in query. Any suggestions?! :-(

Thanks,

G

Comments

greg.harvey’s picture

IMPORTANT: This only occurs when node_db_rewrite_sql() is invoked, so the problem must be happening there, but I've no idea how...

Could it be one of my modules is not exposing a query to that hook and if so, how do I find out which one? :-(

greg.harvey’s picture

I'm talking to myself here, but I'll continue the "conversation", in case someone finds it useful in the future. My hunch about the null query was correct. Within the node_db_rewrite_sql function I put this:

drupal_set_message("Query: ".$query);

Result:

Query: SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC

Query: SELECT n.nid, r.nid AS node_id, c.*, n.title FROM {category} c INNER JOIN {category_node} r ON c.cid = r.cid INNER JOIN {category} cn ON c.cnid = cn.cid INNER JOIN {node} n ON c.cid = n.nid INNER JOIN {node} cnn ON cn.cid = cnn.nid WHERE n.status = 1 AND r.nid = %d ORDER BY cn.weight, cnn.title, c.weight, n.title

And finally!

Query:

AH HA!!
Now I just need to figure out how to find out where this cursed empty query is coming from... Again, any suggestions?

Thanks,

G

keith.smith’s picture

Huh. It seems I've seen some posts recently about queries in lowercase not getting handled by db_rewrite_sql, so that might be one thing to check (for queries that are like "select * from ..."). Just a guess.

--keith

greg.harvey’s picture

Thanks for the reply Keith, but I've searched high and low for a lowercase 'select' and there aren't any. However, the devel module shed more light. It tells me the offending query comes from views_build_view:

views_build_view
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, 10 

Something to go on, at least!

greg.harvey’s picture

Turned out to be a block one of my views is creating - for some reason the views module is sending a null query when trying to build that block, which causes the warning and the malformed SQL.

Yuck!

At least I know what I need to fix now...

agentrickard’s picture

Nice work. Did you file a report over in the Views issue queue?

http://drupal.org/project/issues/views

--
http://ken.blufftontoday.com/
http://new.savannahnow.com/user/2
Search first, ask good questions later.

greg.harvey’s picture

Oops, only just saw your note, but raised an issue: http://drupal.org/node/217015