Use of MySQL-specific SQL in forum.module

intosi - October 24, 2005 - 10:37
Project:Drupal
Version:4.6.3
Component:forum.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

The SQL statemens in forum.module:622 and forum.module:672 use the IF(a,b,c) statement, which is MySQL specific. I run Drupal using PostgreSQL 8. It can be rewritten as

CASE
    WHEN a THEN b
    ELSE c
END

Perhaps someone who is more skilled in Drupal-hacking can point out where I need to implement this (my guess: a custom db_rewrite_sql in includes/database.pgsql.inc).

#1

intosi - October 24, 2005 - 11:18
Status:active» reviewed & tested by the community

The attached patch fixes it on the database-level, by adding two custom functions to the database definition.

AttachmentSize
drupal.2.patch 525 bytes

#2

Cvbge - October 26, 2005 - 13:29

Hi,

there already is IF() function in drupal's database.pgsql. The problem is that it expects a bool type not an integer.
Adding another IF() function that expects integer would fix the problem, but that would require database update in 4.6 series, and I'd prefer not to do it.

Another solution is to change the sql that calls the if() function from IF(l.last_comment_uid, ...) to IF(l.last_comment_uid != 0, .... Attached patch implements this.
last_comment_uid is defined as NOT NULL DEFAULT 0, so it contains only integers. IF(foo, ...) checks if foo is 0 or NULL, so it is the same as IF(foo != 0, ...) in this case (because foo can't be NULL).

I've tested that it works for postgresql.

AttachmentSize
drupal-4-6-postgres-if-35061.diff 2.83 KB

#3

Cvbge - October 26, 2005 - 13:35

Since the situation is the same for HEAD here's the patch for that version.

AttachmentSize
drupal-head-postgres-if-35061.diff 2.76 KB

#4

Cvbge - October 26, 2005 - 13:50

If anyone wanted to test the patch here are the instructions on how to reproduce the bug: http://drupal.org/node/28996

#5

Gerhard Killesreiter - October 26, 2005 - 15:08

query gives same results for mysql.

#6

Dries - October 28, 2005 - 13:46
Status:reviewed & tested by the community» fixed

Commited to HEAD and DRUPAL-4-6. Thanks.

#7

Anonymous - November 11, 2005 - 14:00
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.