From 3bc1da0543f9e4c10961eee158d95136830c3cec Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 7 May 2012 17:07:30 +1200 Subject: [PATCH] MINOR Tidy up of SQLQuery constructor docs and default args, limit is stored internally as an array, not a string. --- model/SQLQuery.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/model/SQLQuery.php b/model/SQLQuery.php index f7d19f603..b85efd299 100644 --- a/model/SQLQuery.php +++ b/model/SQLQuery.php @@ -60,7 +60,7 @@ class SQLQuery { * * @var string */ - protected $limit; + protected $limit = array(); /** * If this is true DISTINCT will be added to the SQL. @@ -98,22 +98,18 @@ class SQLQuery { /** * Construct a new SQLQuery. - * - * @param array $select An array of fields to select. - * @param array $from An array of join clauses. The first one should be just the table name. - * @param array $where An array of filters, to be inserted into the WHERE clause. - * @param string $orderby An ORDER BY clause. - * @param array $groupby An array of fields to group by. - * @param array $having An array of having clauses. - * @param string $limit A LIMIT clause. - * - * TODO: perhaps we can quote things here instead of requiring all the parameters to be quoted - * by this stage. + * + * @param array $select An array of SELECT fields. + * @param array $from An array of FROM clauses. The first one should be just the table name. + * @param array $where An array of WHERE clauses. + * @param array $orderby An array ORDER BY clause. + * @param array $groupby An array of GROUP BY clauses. + * @param array $having An array of HAVING clauses. + * @param array|string $limit A LIMIT clause or array with limit and offset keys */ - function __construct($select = "*", $from = array(), $where = "", $orderby = "", $groupby = "", $having = "", $limit = "") { + function __construct($select = "*", $from = array(), $where = array(), $orderby = array(), $groupby = array(), $having = array(), $limit = array()) { $this->setSelect($select); - // @todo - $this->from = is_array($from) ? $from : array(str_replace(array('"','`'),'',$from) => $from); + $this->setFrom($from); $this->setWhere($where); $this->setOrderBy($orderby); $this->setGroupBy($groupby); @@ -417,8 +413,8 @@ class SQLQuery { } /** - * Get limit clause - * @return string + * Get the limit property. + * @return array */ public function getLimit() { return $this->limit; @@ -438,17 +434,16 @@ class SQLQuery { 'limit' => $limit, ); } else if($limit && is_string($limit)) { - if(strpos($limit,',') !== false) list($start, $innerLimit) = explode(',', $limit, 2); + if(strpos($limit, ',') !== false) list($start, $innerLimit) = explode(',', $limit, 2); else list($innerLimit, $start) = explode(' OFFSET ', strtoupper($limit), 2); $this->limit = array( 'start' => trim($start), 'limit' => trim($innerLimit), ); - } else { $this->limit = $limit; } - + return $this; }