Welcome Guest, Not a member yet? Register   Sign In
'OR Like' MySQL - Maybe a bug?
#4

[eluser]jvicab[/eluser]
This is due to CI doesn't enclose the items in OR section between parenthesis so if the query has AND or other statements the operator's precedence is not what we want.
I have two solutions for this, which I have posted on my blog (www.jvicab.com/blog/articledetails/12).
One of them is adding two functions to DB_active_rec.php (one to deal with or_where and another for or_like. both have the same problem) which properly encloses the OR items. The other is to use native CI where() (or like()) function to build the query as we want.
This is the functions I added to my DB_active_rec.php:
Code:
function like_brackets()
  {
    end($this->ar_like);
    $key = key($this->ar_like);
    // add a bracket close
    $this->ar_like[$key] .= ')';

    // add a bracket open
    reset($this->ar_like);
    $key = key($this->ar_like);
    $this->ar_like[$key] = '('.$this->ar_like[$key];

    // update the AR cache clauses as well
    if ($this->ar_caching === TRUE)
       $this->ar_cache_like[$key] = $this->ar_like[$key];
    return $this;
  }
  
  function where_brackets()
  {
    end($this->ar_where);
    $key = key($this->ar_where);
    // add a bracket close
    $this->ar_where[$key] .= ')';

    // add a bracket open
    reset($this->ar_where);
    $key = key($this->ar_where);
    $this->ar_where[$key] = '('.$this->ar_lar_whereke[$key];

    // update the AR cache clauses as well
    if ($this->ar_caching === TRUE)
       $this->ar_cache_where[$key] = $this->ar_where[$key];
    return $this;
  }

If you need more info, you can visit the ULR I provided or email me.


Messages In This Thread
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-27-2013, 07:22 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 01:09 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 08:07 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB