CodeIgniter Forums
Active Record substring problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Record substring problem (/showthread.php?tid=25504)



Active Record substring problem - El Forum - 12-14-2009

[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");



Active Record substring problem - El Forum - 12-15-2009

[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.


Active Record substring problem - El Forum - 02-25-2010

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

Any ideas why CI is doing this?


Active Record substring problem - El Forum - 06-07-2012

[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


Active Record substring problem - El Forum - 06-07-2012

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