Ambiguous column reference in block_box_get()

kg9ov - January 13, 2007 - 18:30
Project:Drupal
Version:5.x-dev
Component:block.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

After adding a new block and saving, going back to configure the block results in an empty form.

pg_query(): Query failed: ERROR: column reference "title" is ambiguous in /var/www/drupal/drupal-5.0-rc2/includes/database.pgsql.inc on line 125.

query: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = 5 in /var/www/drupal/drupal-5.0-rc2/includes/database.pgsql.inc on line 144.

Adding bl reference to "title" column in block_box_get() fixes this on my install.

# diff block.module.orig block.module
362c362
<   return db_fetch_array(db_query("SELECT bx.*, title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));
---
>   return db_fetch_array(db_query("SELECT bx.*, bl.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));

Server
OS: Debian 3.1 (Sarge)
Web Server: Apache 2.0.54
PHP: 4.3.10
DB: Postgres 7.4.7
Drupal: 5.0rc2

#1

ulyses - January 25, 2007 - 11:48

The problem seems to still exist in Drupal 5.0 Release.

Server
OS: Windows XP SP2
Web Server: Apache 2.2.4
PHP: 5.2.0
DB: Postgres 8.2
Drupal: 5.0

Best regards,
John

#2

mdixoncm - February 18, 2007 - 20:04
Version:5.0-rc2» 5.1

We have just experienced this problem.

The issue can be resolved by changing line 362 to

  return db_fetch_array(db_query("SELECT bx.*, bx.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = %d", $bid));

I'll add this to a patch in a minute.

#3

mdixoncm - February 18, 2007 - 21:16
Status:active» patch (code needs review)

Patch implemented ready for review

AttachmentSize
block-module-patch.txt0 bytes

#4

mdixoncm - February 18, 2007 - 21:17

That last file didn't upload correctly ... this one should be ok

AttachmentSize
bug-109104-patch.txt730 bytes

#5

rdibble - February 25, 2007 - 01:05

I had get the same messages in drupal 5.1 on the site I'm working on....
* warning: pg_query() [function.pg-query]: Query failed: ERROR: column reference "title" is ambiguous LINE 1: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.... ^ in /var/www/virtual-drake/drake-prod/includes/database.pgsql.inc on line 125.
* user warning: query: SELECT bx.*, title FROM boxes bx INNER JOIN blocks bl ON bx.bid = bl.delta WHERE module = 'block' AND bid = 1 in /var/www/virtual-drake/drake-prod/includes/database.pgsql.inc on line 144.

Thanks for the info on how to patch.

#6

jpolt - April 7, 2007 - 17:36

The same patch fixed it for me

Drupal 5.1
PostgreSQL 8.2

#7

Zen - April 11, 2007 - 10:51
Version:5.1» 6.x-dev

That should be bl.title not bx.title. It is the blocks table that has the title field and not the boxes table. Attached patch also adds missing aliases in other parts of the query.

Please review and set to "Ready to be committed" if the attached patch works for you. I'm not sure how adding bx.title worked for anybody as that should have spat out an unknown field error.

FYI: I've tested this only on MySQL.

Thanks,
-K

AttachmentSize
box-query.patch748 bytes

#8

Zen - April 11, 2007 - 10:52

P.S. The above patch applies on both 6 and 5 with offsets.

#9

stormsweeper - April 12, 2007 - 00:03

The cause here may be the drop column query in system.install isn't being executed in system_update_1006(). That was the case for me, although the rest of that update did go through (dropping the constraint, etc).

#10

Dries - April 13, 2007 - 08:33

Ah, can you guys look at the drop-query too? Let's make sure we're fixing the problem at the right level, eh. :)

#11

Zen - April 23, 2007 - 16:17
Status:patch (code needs review)» patch (reviewed & tested by the community)

@Dries: The pgSQL query in question appears to be OK. However, there were other inconsistencies with the syntax and I've created an issue for it: http://drupal.org/node/138556

http://drupal.org/node/132775 (a dupe) also has the same fix. Marking this RTBC.

-K

#12

drewish - May 18, 2007 - 17:15

I'm getting the same error on MySQL and this patch corrects it.

#13

drewish - May 18, 2007 - 17:22

Just for future searchers, I'm getting this error as a side effect of the query:

PHP Fatal error:  Unsupported operand types in D:\drupal\drupalhead\modules\block\block.module on line 592

#14

Dries - May 20, 2007 - 16:40
Version:6.x-dev» 5.x-dev

Committed to CVS HEAD. I think this needs to go into Drupal 5 too.

#15

drumm - May 21, 2007 - 01:38

Committed to 5.

#16

drumm - May 21, 2007 - 01:39
Status:patch (reviewed & tested by the community)» fixed

#17

Anonymous - June 4, 2007 - 21:23
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.