CodeIgniter Forums
Active Record "from" question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Active Record "from" question (/showthread.php?tid=19201)



Active Record "from" question - El Forum - 05-31-2009

[eluser]ReGeDa[/eluser]
I have some problem with active record. My database (PostgreSQL) logic consist of some functions like this:

Code:
create function get_data(int,int) returns setof timeline as $$
select * from smth_table where param1 = $1 and param2 = $2
$$ language sql immutable;

Problem at this:

Code:
//...
$table = 'get_data('.$param1.','.$param1.')';
$this->db->from($table);
//...

It's provides failure escaping:

Code:
... get_data(1,"2)"

My solve replaces to:

Code:
// (system/database/DB_active_rec.php:272)
foreach(preg_split('/,[\s]+/', $val, -1, PREG_SPLIT_NO_EMPTY) as $v)
//...

That is, any table statement separated by ", " (with following space)

Code:
//...
$this->db->from('foo, bar, hello(1,1)');
//...

Maybe other ideas...

:roll: Sorry for English