Bug 8164: Replace IFNULL with COALESCE
authorJonathan Druart <jonathan.druart@biblibre.com>
Thu, 23 Aug 2012 14:36:24 +0000 (16:36 +0200)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Thu, 29 Nov 2012 00:08:29 +0000 (19:08 -0500)
mysql> SELECT IFNULL(0, 123);
+----------------+
| IFNULL(0, 123) |
+----------------+
|              0 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT IFNULL(1, 123);
+----------------+
| IFNULL(1, 123) |
+----------------+
|              1 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT IFNULL(NULL, 123);
+-------------------+
| IFNULL(NULL, 123) |
+-------------------+
|               123 |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT COALESCE(0, 123);
+------------------+
| COALESCE(0, 123) |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT COALESCE(1, 123);
+------------------+
| COALESCE(1, 123) |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT COALESCE(NULL, 123);
+---------------------+
| COALESCE(NULL, 123) |
+---------------------+
|                 123 |
+---------------------+
1 row in set (0.00 sec)

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
C4/Acquisition.pm
C4/Bookseller.pm
C4/VirtualShelves.pm

index 83031be..17330e5 100644 (file)
@@ -1795,8 +1795,8 @@ sub GetLateOrders {
     my $having = "";
     if ($dbdriver eq "mysql") {
         $select .= "
-        aqorders.quantity - IFNULL(aqorders.quantityreceived,0)                 AS quantity,
-        (aqorders.quantity - IFNULL(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
+        aqorders.quantity - COALESCE(aqorders.quantityreceived,0)                 AS quantity,
+        (aqorders.quantity - COALESCE(aqorders.quantityreceived,0)) * aqorders.rrp AS subtotal,
         DATEDIFF(CAST(now() AS date),closedate) AS latesince
         ";
         if ( defined $delay ) {
index 5874a93..c8389a3 100644 (file)
@@ -125,7 +125,7 @@ sub GetBooksellersWithLateOrders {
             )
             AND aqorders.rrp <> 0
             AND aqorders.ecost <> 0
-            AND aqorders.quantity - IFNULL(aqorders.quantityreceived,0) <> 0
+            AND aqorders.quantity - COALESCE(aqorders.quantityreceived,0) <> 0
             AND aqbasket.closedate IS NOT NULL
     ";
     if ( defined $delay ) {
index 5682a15..b7b0c77 100644 (file)
@@ -460,7 +460,7 @@ sub ShelfPossibleAction {
 
     my $dbh = C4::Context->dbh;
     my $query = qq/
-        SELECT IFNULL(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, IFNULL(sh.borrowernumber,0) AS borrowernumber
+        SELECT COALESCE(owner,0) AS owner, category, allow_add, allow_delete_own, allow_delete_other, COALESCE(sh.borrowernumber,0) AS borrowernumber
         FROM virtualshelves vs
         LEFT JOIN virtualshelfshares sh ON sh.shelfnumber=vs.shelfnumber
         AND sh.borrowernumber=?