Welcome Guest, Not a member yet? Register   Sign In
Oracle double Escaping on Like Statements CI 2.1.2 (Active record)
#1

[eluser]Unknown[/eluser]
Hi there,

just in case someone hits this problem:

I had double escapings on underscores in like statements. Example on a rendered query:

SELECT field FROM table WHERE field LIKE 'VALUE!!_%' escape '!'

The problem lies in /system/database/drivers/oci8/oci8_driver line 411 - 413:
Code:
$str = str_replace( array('%', '_', $this->_like_escape_chr),
        array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
        $str);

The order for replacing chars is wrong. Within the replacement, _ is going to be escaped to !_, which is then replaced to !!_.

Solution:
Code:
$str = str_replace( array($this->_like_escape_chr, '%', '_'),
        array( $this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
        $str);

This problem seems to be fixed in the current github-Version. The escaping order seems to be correct there.

Hope it helps anyone.
#2

[eluser]Unknown[/eluser]
Thanks - problem also exists in postgre driver.




Theme © iAndrew 2016 - Forum software by © MyBB