From 8b92b3019821f5f619a95a0b58b62e3bb43dd455 Mon Sep 17 00:00:00 2001 From: Jamie Matthews Date: Sat, 22 Jan 2011 11:08:47 +0000 Subject: Add support for DISTINCT - issue #13 --- idiorm.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'idiorm.php') diff --git a/idiorm.php b/idiorm.php index 61bb96a..e8713d6 100644 --- a/idiorm.php +++ b/idiorm.php @@ -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; @@ -464,6 +467,14 @@ return $this->_add_result_column($expr, $alias); } + /** + * 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. * @@ -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); } -- cgit v1.2.3