Commit c480e19b authored by Taylor Otwell's avatar Taylor Otwell

Added better support for aliases column to Query class.

parent 4ace7c8f
......@@ -120,8 +120,41 @@ class Query {
public function select()
{
$this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
$this->select .= implode(', ', array_map(array($this, 'wrap'), func_get_args()));
$columns = array();
foreach (func_get_args() as $column)
{
// ---------------------------------------------------------
// If the column name is being aliases, we will need to
// wrap the column name and its alias.
// ---------------------------------------------------------
if (strpos(strtolower($column), ' as ') !== false)
{
$segments = explode(' ', $column);
$columns[] = $this->wrap($segments[0]).' AS '.$this->wrap($segments[2]);
}
else
{
$columns[] = $this->wrap($column);
}
}
$this->select .= implode(', ', $columns);
return $this;
}
/**
* Set the FROM clause.
*
* @param string $from
* @return Query
*/
public function from($from)
{
$this->from = $from;
return $this;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment