mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX postgres can filter on non text fields
Filtering non text fields in postgres would cause the SQL to fail. This casts the field to text before the LIKE filter.
This commit is contained in:
parent
d9b0d14ee9
commit
85de3866df
@ -16,13 +16,14 @@ class PartialMatchFilter extends SearchFilter {
|
||||
$this->model = $query->applyRelation($this->relation);
|
||||
$where = array();
|
||||
$comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE';
|
||||
$dbname = (DB::getConn() instanceof PostgreSQLDatabase) ? $this->getDbName().'::text' : $this->getDbName();
|
||||
if(is_array($this->getValue())) {
|
||||
foreach($this->getValue() as $value) {
|
||||
$where[]= sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
|
||||
$where[]= sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($value));
|
||||
}
|
||||
|
||||
} else {
|
||||
$where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
|
||||
$where[] = sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($this->getValue()));
|
||||
}
|
||||
|
||||
return $query->where(implode(' OR ', $where));
|
||||
|
Loading…
Reference in New Issue
Block a user