Welcome Guest, Not a member yet? Register   Sign In
ODBC and LIKE gives weird query
#1

Hi,

I'm trying to make a simple query in Codigniter v3.0.0 like this:

PHP Code:
$this->db->select("cats");
$this->db->from("pets");
$this->db->like("name"'a''after'); 


And then show it:

PHP Code:
echo $this->db->get_compiled_select(); 


Result:

Quote:SELECT cats FROM pets WHERE name LIKE 'a%' {escape '!'}

For some reason CI adds {escape '!'} at the end. Which of course generates an error when I try to run the query.

Database config:

PHP Code:
$db['pyramid'] = array(
'dsn'   => 'pyramid',
'hostname' => '',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'odbc',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'WINDOWS-1252',
'dbcollat' => '',
    //'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
); 

I have tried to change the file system/database/drivers/odbc/odbc_driver.php like this:


PHP Code:
//protected $_like_escape_str = " {escape '%s'} "; Original
protected $_like_escape_str ""//Replaced with an empty string 

It seems to escape as it should, but I'm not sure if something else depends on this.

Is this a bug or is it just me that don't know how to use it properly? Undecided
Does anyone know how to fix this?
Reply
#2

You may want to try upgrading to 3.0.4, as there were a few fixes to the database library in each version since 3.0. As far as I can tell, the output should look something like the following:

Code:
SELECT cats FROM pets WHERE name LIKE 'a!%' {escape '!'}

For reference:
https://msdn.microsoft.com/en-us/library...85%29.aspx
Reply
#3

(02-16-2016, 02:55 PM)mwhitney Wrote: You may want to try upgrading to 3.0.4, as there were a few fixes to the database library in each version since 3.0. As far as I can tell, the output should look something like the following:

Code:
SELECT cats FROM pets WHERE name LIKE 'a!%' {escape '!'}

For reference:
https://msdn.microsoft.com/en-us/library...85%29.aspx

Thank you for your response!

I have now upgraded to 3.0.4 but still no luck.

I also tried this:

Code:
$this->db->where("name LIKE '" . $this->db->escape_like_str('a%') . "' {escape '!'}", NULL, FALSE);

and

Code:
$this->db->where("name LIKE '" . $this->db->escape_like_str('a') . "%' {escape '!'}", NULL, FALSE);


Both of these give me a database syntax error (as before).
It doesn't seems to accept the {escape '!'} part.

Could it be due to the fact that there is a Pervasive database?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB