Skip to content

Commit

Permalink
fix #4479 by ensuring subquery in findNewIds never returns NULL
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Bender <patrick@bender-it-services.de>
  • Loading branch information
IchbinkeinReh committed Jul 2, 2023
1 parent 45e2e8d commit 08bd4fc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,9 @@ public function findNewIds(Mailbox $mailbox, array $ids): array {
$select = $this->db->getQueryBuilder();
$subSelect = $this->db->getQueryBuilder();

// MIN returns NULL if there are no rows selected, therefore we use COALESCE to ensure 0 is returned in this case
$subSelect
->select($subSelect->func()->min('sent_at'))
->select($subSelect->createFunction('COALESCE(MIN(' . $subSelect->getColumnName('sent_at') . '), 0)'))
->from($this->getTableName())
->where(
$subSelect->expr()->eq('mailbox_id', $select->createNamedParameter($mailbox->getId(), IQueryBuilder::PARAM_INT)),
Expand Down

0 comments on commit 08bd4fc

Please sign in to comment.