Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#5 | heartbeat-n1882170-5.patch | 917 bytes | DamienMcKenna |
coalesce_insteadof_ifnull-0.patch | 1.01 KB | girishmuraly |
Comments
Comment #1
girishmuraly CreditAttribution: girishmuraly commentedSetting patch attached in first comment to needs review.
Comment #2
Stalski CreditAttribution: Stalski commentedGreat. Did not know that but I am happy to learn that.
Thx for the patch.
Comment #3
ramsunvtech CreditAttribution: 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.