When trying to view a book page, with a book block shown on book pages only, I get the following error as an "Authenticated User" and not as an "Administrator":

PDOException: SQLSTATE[HY000]: General error: 1 ambiguous column name: nid: SELECT DISTINCT node.title AS title FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid = :db_condition_placeholder_0) AND(( (na.gid = :db_condition_placeholder_1) AND (na.realm = :db_condition_placeholder_2) )OR( (na.gid = :db_condition_placeholder_3) AND (na.realm = :db_condition_placeholder_4) )OR( (na.gid = :db_condition_placeholder_5) AND (na.realm = :db_condition_placeholder_6) )OR( (na.gid = :db_condition_placeholder_7) AND (na.realm = :db_condition_placeholder_8) ))AND (na.grant_view >= :db_condition_placeholder_9) ; Array ( [:db_condition_placeholder_0] => 16 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => all [:db_condition_placeholder_3] => 10 [:db_condition_placeholder_4] => acl [:db_condition_placeholder_5] => 20 [:db_condition_placeholder_6] => content_access_author [:db_condition_placeholder_7] => 2 [:db_condition_placeholder_8] => content_access_rid [:db_condition_placeholder_9] => 1 ) in book_block_view() (line 287 of C:\xampp\htdocs\drupal\modules\book\book.module).

You will note that the string WHERE (nid = :db_condition_placeholder_0) is missing it's table specifier. This should read "node.nid" or perhaps "na.nid" instead of just "nid".

Line 287 of book.module is this: $title = $select->execute()->fetchField();

This appears to have something to do with the call $select = db_select('node'); earlier, so I've put it under "database system" rather than book.module.

Comments

adamskinner’s picture

Component: database system » book.module
StatusFileSize
new713 bytes

I did some more poking around this morning, and was able to resolve the issue. It occurred due to a lack of a table alias for the node table.

To replicate this issue, create a book and set a block for it. View the block as an administrator, and then as a regular user. The regular user will get the error above prior to the patch, and after the patch they are able to view the page.

[edit] A patch is attached, but I did it backwards. Use the subsequent one instead.

adamskinner’s picture

StatusFileSize
new713 bytes

My previous patch had the filenames in reverse position. The new patch reads thusly:

--- C:/Adam/Drupal/drupal-7.0/modules/book/book.module	Mon Jan 03 02:34:46 2011
+++ C:/xampp/htdocs/drupal/modules/book/book.module	Wed Mar 30 10:03:17 2011
@@ -280,9 +280,9 @@
   }
   elseif ($current_bid) {
     // Only display this block when the user is browsing a book.
-    $select = db_select('node');
-    $select->addField('node', 'title');
-    $select->condition('nid', $node->book['bid']);
+    $select = db_select('node', 'n');
+    $select->addField('n', 'title');
+    $select->condition('n.nid', $node->book['bid']);
     $select->addTag('node_access');
     $title = $select->execute()->fetchField();
     // Only show the block if the user has view access for the top-level node.
bfroehle’s picture

Status: Active » Needs review
StatusFileSize
new738 bytes

I've attached @adamskinner's patch in #2 in a format compatible with the test bot. I have not, however, reviewed the patch.

Anonymous’s picture

I can confirm this bug is still alive and kicking on 7.2. The alias for node is missing, just that little fix. Please fix it!

JimmyAx’s picture

Status: Needs review » Closed (fixed)

I suggest using #1013864: Book navigation block fails with Node Access modules as it's the original issue for this problem. The patch in #3 is outdated by now and has been updated in #1013864.