• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Record substring problem

#1
[eluser]webb_design[/eluser]
Why is the Active Record class removing multiple substrings in my query? I'm trying to do something like this:

Code:
SELECT CONCAT_WS('-', SUBSTRING(test, 1, 5), SUBSTRING(test, 6, 5)) AS testing

But it's returning this:

Code:
SELECT CONCAT_WS('-', SUBSTRING(test, 1, 5), 6, 5)) AS testing

How can I prevent this from happening?

Thanks.

UPDATE

The above is the final query, in code I'm doing this:

Code:
$this->db-select("CONCAT_WS('-', SUBSTRING(test, 1, 5), SUBSTRING(test, 6, 5)) AS testing");

#2
[eluser]webb_design[/eluser]
Got a workaround for now. When I use aliases of SUBSTRING (SUBSTR and MID), CI doesn't remove them. Here's what I did instead:

Code:
$this->db->select("CONCAT_WS('-', SUBSTRING(test, 1, 5), SUBSTR(test, 6, 10)) AS testing");

But... this is a pretty dumb hack. Does anyone know why CI is removing the multiple SUBSTRINGs? It almost seems like it's trying to combine them together. I tried overloading the select() method with FALSE to disable escaping but that didn't help.

Thanks.

#3
[eluser]webb_design[/eluser]
Bringing this back from the dead...

Any ideas why CI is doing this?

#4
[eluser]Unknown[/eluser]
The solution is very simple.
Just should add new element in array with default database settings.
File location: ./application/config/database.php

Add line:
$db['default']['_protect_identifiers']= FALSE;

Best Regards

#5
[eluser]CroNiX[/eluser]
Check out what the 2nd parameter to db:Confusedelect() is used for Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.