Don't add a LIKE condition when it's not needed

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2017-09-24 15:24:08 +02:00 committed by Roeland Jago Douma
parent 199c4b2ff9
commit f1bfd4433e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 5 additions and 1 deletions

View File

@ -890,7 +890,11 @@ class CardDavBackend implements BackendInterface, SyncSupport {
$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())));