I was looking up the use of IFNULL() expression in db queries in Drupal and I found this module using it in HeartbeatStream::createQuery() (includes/heartbeatstream.inc).

// The user_access field holds the least access known. (NULL = HEARTBEAT_PUBLIC_TO_ALL).
$access_expression = "LEAST ( IFNULL ( ha.access, " . HEARTBEAT_PUBLIC_TO_ALL . "), IFNULL ( hut.status, " . HEARTBEAT_PUBLIC_TO_ALL . "))";

IFNULL is MySQL specific. For portability, use COALESCE as it is generic and is part of standard SQL. Docs from Mysql - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#functio... but it is the same function syntax for PostgreSQL, Oracle and SQL Server.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

girishmuraly’s picture

Status: Active » Needs review

Setting patch attached in first comment to needs review.

Stalski’s picture

Great. Did not know that but I am happy to learn that.
Thx for the patch.

ramsunvtech’s picture

Thanks for the patch. Good thought about Portability.

DamienMcKenna’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Seems good to go, though the SQL statement itself needs updating to match the Drupal coding standards, but that's a separate thing.

DamienMcKenna’s picture

FileSize
917 bytes

Rerolled.