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).

Comments

intosi’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new525 bytes

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

Cvbge’s picture

StatusFileSize
new2.83 KB

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.

Cvbge’s picture

StatusFileSize
new2.76 KB

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

Cvbge’s picture

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

gerhard killesreiter’s picture

query gives same results for mysql.

dries’s picture

Status: Reviewed & tested by the community » Fixed

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

Anonymous’s picture

Status: Fixed » Closed (fixed)