Refactor the database query class.

This commit is contained in:
Taylor Otwell 2011-08-08 10:24:23 -05:00
parent 64fb09a870
commit db391b8090
1 changed files with 3 additions and 14 deletions

View File

@ -527,20 +527,11 @@ public function get($columns = array('*'))
$sql = $this->select.' '.$this->from.' '.$this->where;
if (count($this->orderings) > 0)
{
$sql .= ' ORDER BY '.implode(', ', $this->orderings);
}
if (count($this->orderings) > 0) $sql .= ' ORDER BY '.implode(', ', $this->orderings);
if ( ! is_null($this->limit))
{
$sql .= ' LIMIT '.$this->limit;
}
if ( ! is_null($this->limit)) $sql .= ' LIMIT '.$this->limit;
if ( ! is_null($this->offset))
{
$sql .= ' OFFSET '.$this->offset;
}
if ( ! is_null($this->offset)) $sql .= ' OFFSET '.$this->offset;
$results = $this->connection->query($sql, $this->bindings);
@ -689,13 +680,11 @@ private function parameterize($values)
*/
public function __call($method, $parameters)
{
// Dynamically handle the addition of dynamic where clauses.
if (strpos($method, 'where_') === 0)
{
return $this->dynamic_where($method, $parameters, $this);
}
// Dynamically handle calls to any of the aggregate query functions.
if (in_array($method, array('count', 'min', 'max', 'avg', 'sum')))
{
return ($method == 'count') ? $this->aggregate(strtoupper($method), '*') : $this->aggregate(strtoupper($method), $parameters[0]);