diff options
author | Jamie Matthews <[email protected]> | 2011-01-22 11:08:47 +0000 |
---|---|---|
committer | Jamie Matthews <[email protected]> | 2011-01-22 11:08:47 +0000 |
commit | 8b92b3019821f5f619a95a0b58b62e3bb43dd455 (patch) | |
tree | c81d963bf8c8658fcff4024e04204399a2461d59 /idiorm.php | |
parent | 68a66e0b0a1b89af4fcd1e8cad9c1b988c92ce07 (diff) |
Add support for DISTINCT - issue #13
Diffstat (limited to 'idiorm.php')
-rw-r--r-- | idiorm.php | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -100,6 +100,9 @@ // Join sources protected $_join_sources = array(); + // Should the query include a DISTINCT keyword? + protected $_distinct = false; + // Is this a raw query? protected $_is_raw_query = false; @@ -465,6 +468,14 @@ } /** + * Add a DISTINCT keyword before the list of columns in the SELECT query + */ + public function distinct() { + $this->_distinct = true; + return $this; + } + + /** * Internal method to add a JOIN source to the query. * * The join_operator should be one of INNER, LEFT OUTER, CROSS etc - this @@ -763,7 +774,13 @@ */ protected function _build_select_start() { $result_columns = join(', ', $this->_result_columns); + + if ($this->_distinct) { + $result_columns = 'DISTINCT ' . $result_columns; + } + $fragment = "SELECT {$result_columns} FROM " . $this->_quote_identifier($this->_table_name); + if (!is_null($this->_table_alias)) { $fragment .= " " . $this->_quote_identifier($this->_table_alias); } |