Skip to content

Commit

Permalink
Merge pull request #6633 from nextcloud/dav-remove-like-when-not-needed
Browse files Browse the repository at this point in the history
Don't add a LIKE condition when it's not needed
  • Loading branch information
nickvergessen authored Sep 25, 2017
2 parents 4677af1 + f1bfd44 commit e0a4c61
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,11 @@ public function search($addressBookId, $pattern, $searchProperties) {
$or->add($query2->expr()->eq('cp.name', $query->createNamedParameter($property)));
}
$query2->andWhere($or);
$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));

// No need for like when the pattern is empty
if ('' !== $pattern) {
$query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%')));
}

$query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c')
->where($query->expr()->in('c.id', $query->createFunction($query2->getSQL())));
Expand Down

0 comments on commit e0a4c61

Please sign in to comment.