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.
Comments
Comment #1
girishmuraly commentedSetting patch attached in first comment to needs review.
Comment #2
Stalski commentedGreat. Did not know that but I am happy to learn that.
Thx for the patch.
Comment #3
ramsunvtech commentedThanks for the patch. Good thought about Portability.
Comment #4
damienmckennaSeems good to go, though the SQL statement itself needs updating to match the Drupal coding standards, but that's a separate thing.
Comment #5
damienmckennaRerolled.