where, or_where and or_like mixes #63

bitbucket-import opened this Issue Aug 19, 2011 · 3 comments

4 participants



I'm using this code:

$this->db->where('CustomerId', $searchString);
$this->db->or_where('TaxId', $searchString);
$this->db->or_like('CompanyName ', $searchString, 'both');
$this->db->or_like('Contact ', $searchString, 'both');
$this->db->or_like('ba.City ', $searchString, 'both');

but the sql formed is:
WHERE CustomerId = 'SONAE'
OR TaxId = 'SONAE'
AND CompanyName LIKE '%SONAE%'
OR Contact LIKE '%SONAE%'
OR ba.City LIKE '%SONAE%'

That AND is wrong.


I made the PR#1030 for this issue.


I have a similar problem.

I use this in a loop to programatically produce search queries.

$this->db->or_where('part.coef', $coef);
$this->db->where('part.exp', $exp);

I expect coef AND exp OR ..... but instead get:

WHERE "part"."coef" = 1 OR "part"."exp" = -7 AND lower(part.name) LIKE '%100n%' ESCAPE '!' OR lower(part.type) LIKE '%100n%' ESCAPE '!' OR lower(part.nbr) LIKE '%100n%' ESCAPE '!' OR lower(manufacturer.name) LIKE '%100n%' ESCAPE '!' OR lower(part_family.name) LIKE '%100n%' ESCAPE '!' OR lower(symbol.name) LIKE '%100n%' ESCAPE '!' OR lower(footprint.name) LIKE '%100n%' ESCAPE '!'


I have solved this problem by using:
$this->db->or_where("(part.coef=$coef AND part.exp=$exp)", null ,FALSE);
$this->db->or_like(array("part.name"=>""), false);

the second line just creates a condition that never fails. The resulting condition is: (part.coef=$coef AND part.exp=$exp) AND alwaystrue OR ......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment