From 96feb586c7fc2c232675590fe4e1032198a39535 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 13:12:34 +0300 Subject: Implement group_by() compiler and no_escape feature --- system/database/DB_query_builder.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 55b97bb3f..6c247f957 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -879,21 +879,24 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function group_by($by, $escape = NULL) { + is_bool($escape) OR $escape = $this->_protect_identifiers; + if (is_string($by)) { - $by = explode(',', $by); + $by = ($escape === TRUE) + ? explode(',', $by) + : array($by); } - is_bool($escape) OR $escape = $this->_protect_identifiers; - foreach ($by as $val) { $val = trim($val); if ($val !== '') { - $this->qb_groupby[] = $val = $this->protect_identifiers($val); + $val = array('field' => $val, 'escape' => $escape); + $this->qb_groupby[] = $val; if ($this->qb_caching === TRUE) { $this->qb_cache_groupby[] = $val; @@ -2118,6 +2121,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { $sql = "\nGROUP BY "; + for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) + { + $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE) + ? $this->qb_groupby[$i]['field'] + : $this->protect_identifiers($qb_groupby[$i]['field']); + } + $sql .= implode(', ', $this->qb_groupby); } -- cgit v1.2.3-24-g4f1b