Welcome Guest, Not a member yet? Register   Sign In
Overzealous escaping of queries
#1

[eluser]beseku[/eluser]
Spot the error:
Code:
SELECT CONCAT(TRIM(`LEADING` '.' `FROM` CONCAT(p1.genealogy, p1.id)), '.') AS genealogy, p1.*, COUNT(p2.id) - COUNT(ps2.id) AS children, ROUND(COUNT(ps1.page_id) / (COUNT(ps1.page_id))) AS suspended, u.id AS user_id, u.email AS user_email, u.name AS user_name FROM (`gcms9_pages` p1) LEFT JOIN `gcms9_pages` p2 ON CONCAT(TRIM(LEADING '.' FROM CONCAT(p1.genealogy, p1.id)), '.') = p2.genealogy LEFT JOIN `gcms9_pages_suspended` ps1 ON p1.id = ps1.page_id LEFT JOIN `gcms9_pages_suspended` ps2 ON p2.id = ps2.page_id LEFT JOIN `gcms9_users` u ON p1.user_id = u.id WHERE p1.id = '5' AND p1.id NOT IN (SELECT ps.page_id FROM gcms9_pages_suspended ps) GROUP BY p1.id ORDER BY p1.sequence ASC LIMIT 1

From:
Code:
$this->db->select("CONCAT(TRIM(LEADING '.' FROM CONCAT(p1.genealogy, p1.id)), '.') AS genealogy");
$this->db->select("p1.*");
$this->db->select("COUNT(p2.id) - COUNT(ps2.id) AS children");
$this->db->select("ROUND(COUNT(ps1.page_id) / (COUNT(ps1.page_id))) AS suspended");
$this->db->select("u.id AS user_id");
$this->db->select("u.email AS user_email");
$this->db->select("u.name AS user_name");
$this->db->from("gcms9_pages p1");
$this->db->join("gcms9_pages p2", "CONCAT(TRIM(LEADING '.' FROM CONCAT(p1.genealogy, p1.id)), '.') = p2.genealogy", "LEFT");
$this->db->join("gcms9_pages_suspended ps1", "p1.id = ps1.page_id", "LEFT");
$this->db->join("gcms9_pages_suspended ps2", "p2.id = ps2.page_id", "LEFT");
$this->db->join("gcms9_users u", "p1.user_id = u.id", "LEFT");
$this->db->groupby("p1.id");
$this->db->orderby("p1.sequence", "ASC");
$this->db->limit($limit, $offset);

Why is the revised active record class escaping proper query structures that worked in 1.5.4?
#2

[eluser]Seppo[/eluser]
CI 1.6 attempts to escape all select "fields". When you are using a function, you have to "declare" you don't want this feature using a second parameter FALSE
Code:
$this->db->select("CONCAT(TRIM(LEADING '.' FROM CONCAT(p1.genealogy, p1.id)), '.') AS genealogy", FALSE);
$this->db->select("p1.*", FALSE);
$this->db->select("COUNT(p2.id) - COUNT(ps2.id) AS children", FALSE);
$this->db->select("ROUND(COUNT(ps1.page_id) / (COUNT(ps1.page_id))) AS suspended", FALSE);
#3

[eluser]beseku[/eluser]
Awesome. I knew I had missed something. Cheers muchly.
#4

[eluser]Derek Allard[/eluser]
Yeah, apologies for the inconvenience here, but it was the only way to allow auto-escaping but allow backwards compatibility.




Theme © iAndrew 2016 - Forum software by © MyBB