Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where, or_where and or_like mixes #63

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

where, or_where and or_like mixes #63

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

Comments

@bitbucket-import
Copy link

Hi,

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.

@grandbora
Copy link

I made the PR#1030 for this issue.

@schneidersoft
Copy link

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);
$this->db->or_like($needles);

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 '!'

@schneidersoft
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants