Make CASE statements more readable in queries in UserConversationList
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 10 Feb 2022 13:57:53 +0000 (14:57 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 10 Feb 2022 13:57:53 +0000 (14:57 +0100)
files/lib/data/conversation/UserConversationList.class.php

index 86024bf66146e01ee0308276600e9498dd7df11b..4c24b19949b79fecae190c363a26c2678a873734 100644 (file)
@@ -103,7 +103,13 @@ class UserConversationList extends ConversationList
                     AND conversation_to_user.conversationID = conversation.conversationID";
 
         if ($this->filter !== 'draft') {
-            $this->sqlSelects .= ", conversation.*, CASE WHEN conversation_to_user.leftAt <> 0 THEN conversation_to_user.leftAt ELSE conversation.lastPostTime END AS lastPostTime";
+            $this->sqlSelects .= ",
+            conversation.*,
+            (CASE
+                WHEN    conversation_to_user.leftAt <> 0
+                THEN    conversation_to_user.leftAt
+                ELSE    conversation.lastPostTime
+            END) AS lastPostTime";
             // this avoids appending `conversation.*` to the SELECT list
             $this->useQualifiedShorthand = false;
         }
@@ -151,7 +157,11 @@ class UserConversationList extends ConversationList
         }
 
         $sql = "SELECT  conversation_to_user.conversationID AS objectID,
-                        CASE WHEN conversation_to_user.leftAt <> 0 THEN conversation_to_user.leftAt ELSE conversation.lastPostTime END AS lastPostTime
+                        (CASE
+                            WHEN    conversation_to_user.leftAt <> 0
+                            THEN    conversation_to_user.leftAt
+                            ELSE    conversation.lastPostTime
+                        END) AS lastPostTime
                 FROM    wcf" . WCF_N . "_conversation_to_user conversation_to_user
                     " . $this->sqlConditionJoins . "
                     " . $this->getConditionBuilder() . "