From 787be6bc99fda3a9f8fdb9c19a6135b6efe099bf Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 8 Jul 2011 07:28:38 -0700 Subject: [PATCH] Changed Query::get and Query::first to accept arrays of columns instead of a dynamic parameter list. --- system/db/query.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/system/db/query.php b/system/db/query.php index fc214799..cc1e5bb2 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -115,15 +115,16 @@ class Query { /** * Add columns to the SELECT clause. * + * @param array $columns * @return Query */ - public function select() + public function select($columns = array('*')) { $this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT '; - $columns = array(); + $wrapped = array(); - foreach (func_get_args() as $column) + foreach ($columns as $column) { // If the column name is being aliased, we will need to wrap the column // name and its alias in keyword identifiers. @@ -131,15 +132,15 @@ class Query { { $segments = explode(' ', $column); - $columns[] = $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]); + $wrapped[] = $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]); } else { - $columns[] = $this->wrap($column); + $wrapped[] = $this->wrap($column); } } - $this->select .= implode(', ', $columns); + $this->select .= implode(', ', $wrapped); return $this; } @@ -388,34 +389,38 @@ class Query { /** * Find a record by the primary key. * - * @param int $id + * @param int $id + * @param array $columns * @return object */ - public function find($id) + public function find($id, $columns = array('*')) { - return $this->where('id', '=', $id)->first(); + return $this->where('id', '=', $id)->first($columns); } /** * Execute the query as a SELECT statement and return the first result. * + * @param array $columns * @return object */ - public function first() + public function first($columns = array('*')) { - return (count($results = call_user_func_array(array($this->take(1), 'get'), func_get_args())) > 0) ? $results[0] : null; + + return (count($results = $this->take(1)->get($columns)) > 0) ? $results[0] : null; } /** * Execute the query as a SELECT statement. * + * @param array $columns * @return array */ - public function get() + public function get($columns = array('*')) { if (is_null($this->select)) { - call_user_func_array(array($this, 'select'), (count(func_get_args()) > 0) ? func_get_args() : array('*')); + $this->select($columns); } return DB::query(Query\Compiler::select($this), $this->bindings, $this->connection);