// Improve DbQuery

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8676 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-09-21 08:12:47 +00:00
parent a3881668f0
commit 734a615464
+23 -23
View File
@@ -72,37 +72,37 @@ class DbQueryCore
/** /**
* Add JOIN clause * Add JOIN clause
* E.g. $this->join('RIGHT JOIN '._DB_PREFIX_.'product p ON ...');
* *
* @param string $type Join type : left|right|inner|cross|union|natural * @param string $join Complete string
* @return DbQuery * @return DbQuery
*/ */
public function join($type, $join) public function join($join)
{ {
$type = strtolower($type); $this->query['join'][] = $join;
$types = array(
'left' => 'LEFT JOIN',
'right' => 'RIGHT JOIN',
'inner' => 'INNER JOIN',
'cross' => 'CROSS JOIN',
'union' => 'UNION JOIN',
'natural' => 'NATURAL JOIN',
);
if (!isset($types[$type]))
die('Bad type in DbQuery->join()');
$this->query['join'][] = $types[$type].' '._DB_PREFIX_.$join;
return $this; return $this;
} }
/**
* Add LEFT JOIN clause
* E.g. $this->leftJoin('product p ON ...')
*
* @param string $join Table followed by ON claused
*/
public function leftJoin($join) public function leftJoin($join)
{ {
return $this->join('left', $join); return $this->join('LEFT JOIN '._DB_PREFIX_.$join);
} }
public function innerJoin($table) /**
* Add INNER JOIN clause
* E.g. $this->innerJoin('product p ON ...')
*
* @param string $join Table followed by ON claused
*/
public function innerJoin($join)
{ {
return $this->join('inner', $join); return $this->join('INNER JOIN '._DB_PREFIX_.$join);
} }
/** /**
@@ -135,7 +135,7 @@ class DbQueryCore
* @param string $fields List of fields to sort. E.g. $this->order('myField, b.mySecondField DESC') * @param string $fields List of fields to sort. E.g. $this->order('myField, b.mySecondField DESC')
* @return DbQuery * @return DbQuery
*/ */
public function order($fields) public function orderBy($fields)
{ {
$this->query['order'][] = $fields; $this->query['order'][] = $fields;
return $this; return $this;
@@ -147,7 +147,7 @@ class DbQueryCore
* @param string $fields List of fields to sort. E.g. $this->group('myField, b.mySecondField DESC') * @param string $fields List of fields to sort. E.g. $this->group('myField, b.mySecondField DESC')
* @return DbQuery * @return DbQuery
*/ */
public function group($fields) public function groupBy($fields)
{ {
$this->query['group'][] = $fields; $this->query['group'][] = $fields;
return $this; return $this;
@@ -189,13 +189,13 @@ class DbQueryCore
$sql .= implode("\n", $this->query['join'])."\n"; $sql .= implode("\n", $this->query['join'])."\n";
if ($this->query['where']) if ($this->query['where'])
$sql .= 'WHERE '.implode(' AND ', $this->query['where'])."\n"; $sql .= 'WHERE ('.implode(') AND (', $this->query['where']).")\n";
if ($this->query['group']) if ($this->query['group'])
$sql .= 'GROUP BY '.implode(', ', $this->query['group'])."\n"; $sql .= 'GROUP BY '.implode(', ', $this->query['group'])."\n";
if ($this->query['having']) if ($this->query['having'])
$sql .= 'HAVING '.implode(' AND ', $this->query['having'])."\n"; $sql .= 'HAVING ('.implode(') AND (', $this->query['having']).")\n";
if ($this->query['order']) if ($this->query['order'])
$sql .= 'ORDER BY '.implode(', ', $this->query['order'])."\n"; $sql .= 'ORDER BY '.implode(', ', $this->query['order'])."\n";