2007-05-21 20:15:20 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id: Query.php 1393 2007-05-19 17:49:16Z zYne $
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.phpdoctrine.com>.
|
|
|
|
*/
|
|
|
|
Doctrine::autoload('Doctrine_Hydrate');
|
|
|
|
/**
|
|
|
|
* Doctrine_Query_Abstract
|
|
|
|
*
|
|
|
|
* @package Doctrine
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @category Object Relational Mapping
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision: 1393 $
|
|
|
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
|
*/
|
|
|
|
abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* addSelect
|
|
|
|
* adds fields to the SELECT part of the query
|
|
|
|
*
|
|
|
|
* @param string $select Query SELECT part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function addSelect($select)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('select', $select, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* addWhere
|
|
|
|
* adds conditions to the WHERE part of the query
|
|
|
|
*
|
|
|
|
* @param string $where Query WHERE part
|
|
|
|
* @param mixed $params an array of parameters or a simple scalar
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function addWhere($where, $params = array())
|
|
|
|
{
|
|
|
|
if (is_array($params)) {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = array_merge($this->_params, $params);
|
2007-05-21 20:15:20 +04:00
|
|
|
} else {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params[] = $params;
|
2007-05-21 20:15:20 +04:00
|
|
|
}
|
|
|
|
return $this->parseQueryPart('where', $where, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* addGroupBy
|
|
|
|
* adds fields to the GROUP BY part of the query
|
|
|
|
*
|
|
|
|
* @param string $groupby Query GROUP BY part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function addGroupBy($groupby)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('groupby', $groupby, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* addHaving
|
|
|
|
* adds conditions to the HAVING part of the query
|
|
|
|
*
|
|
|
|
* @param string $having Query HAVING part
|
|
|
|
* @param mixed $params an array of parameters or a simple scalar
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function addHaving($having, $params = array())
|
|
|
|
{
|
|
|
|
if (is_array($params)) {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = array_merge($this->_params, $params);
|
2007-05-21 20:15:20 +04:00
|
|
|
} else {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params[] = $params;
|
2007-05-21 20:15:20 +04:00
|
|
|
}
|
|
|
|
return $this->parseQueryPart('having', $having, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* addOrderBy
|
|
|
|
* adds fields to the ORDER BY part of the query
|
|
|
|
*
|
|
|
|
* @param string $orderby Query ORDER BY part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function addOrderBy($orderby)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('orderby', $orderby, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* select
|
|
|
|
* sets the SELECT part of the query
|
|
|
|
*
|
|
|
|
* @param string $select Query SELECT part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function select($select)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('select', $select);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* distinct
|
|
|
|
* Makes the query SELECT DISTINCT.
|
|
|
|
*
|
|
|
|
* @param bool $flag Whether or not the SELECT is DISTINCT (default true).
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function distinct($flag = true)
|
|
|
|
{
|
|
|
|
$this->_parts['distinct'] = (bool) $flag;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* forUpdate
|
|
|
|
* Makes the query SELECT FOR UPDATE.
|
|
|
|
*
|
|
|
|
* @param bool $flag Whether or not the SELECT is FOR UPDATE (default true).
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function forUpdate($flag = true)
|
|
|
|
{
|
|
|
|
$this->_parts[self::FOR_UPDATE] = (bool) $flag;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* delete
|
|
|
|
* sets the query type to DELETE
|
|
|
|
*
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$this->type = self::DELETE;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* update
|
|
|
|
* sets the UPDATE part of the query
|
|
|
|
*
|
|
|
|
* @param string $update Query UPDATE part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function update($update)
|
|
|
|
{
|
|
|
|
$this->type = self::UPDATE;
|
|
|
|
|
|
|
|
return $this->parseQueryPart('from', $update);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* set
|
|
|
|
* sets the SET part of the query
|
|
|
|
*
|
|
|
|
* @param string $update Query UPDATE part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function set($key, $value)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('set', $key . ' = ' . $value);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* from
|
|
|
|
* sets the FROM part of the query
|
|
|
|
*
|
|
|
|
* @param string $from Query FROM part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function from($from)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('from', $from);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* innerJoin
|
|
|
|
* appends an INNER JOIN to the FROM part of the query
|
|
|
|
*
|
|
|
|
* @param string $join Query INNER JOIN
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function innerJoin($join)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('from', 'INNER JOIN ' . $join);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* leftJoin
|
|
|
|
* appends a LEFT JOIN to the FROM part of the query
|
|
|
|
*
|
|
|
|
* @param string $join Query LEFT JOIN
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function leftJoin($join)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('from', 'LEFT JOIN ' . $join);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* groupBy
|
|
|
|
* sets the GROUP BY part of the query
|
|
|
|
*
|
|
|
|
* @param string $groupby Query GROUP BY part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function groupBy($groupby)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('groupby', $groupby);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* where
|
|
|
|
* sets the WHERE part of the query
|
|
|
|
*
|
|
|
|
* @param string $join Query WHERE part
|
|
|
|
* @param mixed $params an array of parameters or a simple scalar
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function where($where, $params = array())
|
|
|
|
{
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = array();
|
2007-05-24 17:58:36 +04:00
|
|
|
if (is_array($params)) {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = $params;
|
2007-05-24 17:58:36 +04:00
|
|
|
} else {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params[] = $params;
|
2007-05-24 17:58:36 +04:00
|
|
|
}
|
2007-05-21 20:15:20 +04:00
|
|
|
|
|
|
|
return $this->parseQueryPart('where', $where);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* having
|
|
|
|
* sets the HAVING part of the query
|
|
|
|
*
|
|
|
|
* @param string $having Query HAVING part
|
|
|
|
* @param mixed $params an array of parameters or a simple scalar
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
2007-05-24 17:52:30 +04:00
|
|
|
public function having($having, $params = array())
|
2007-05-21 20:15:20 +04:00
|
|
|
{
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = array();
|
2007-05-24 17:58:36 +04:00
|
|
|
if (is_array($params)) {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params = $params;
|
2007-05-24 17:58:36 +04:00
|
|
|
} else {
|
2007-05-24 21:49:15 +04:00
|
|
|
$this->_params[] = $params;
|
2007-05-24 17:58:36 +04:00
|
|
|
}
|
2007-05-21 20:15:20 +04:00
|
|
|
|
|
|
|
return $this->parseQueryPart('having', $having);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* orderBy
|
|
|
|
* sets the ORDER BY part of the query
|
|
|
|
*
|
|
|
|
* @param string $orderby Query ORDER BY part
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function orderBy($orderby)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('orderby', $orderby);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* limit
|
|
|
|
* sets the Query query limit
|
|
|
|
*
|
|
|
|
* @param integer $limit limit to be used for limiting the query results
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function limit($limit)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('limit', $limit);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* offset
|
|
|
|
* sets the Query query offset
|
|
|
|
*
|
|
|
|
* @param integer $offset offset to be used for paginating the query
|
|
|
|
* @return Doctrine_Query
|
|
|
|
*/
|
|
|
|
public function offset($offset)
|
|
|
|
{
|
|
|
|
return $this->parseQueryPart('offset', $offset);
|
|
|
|
}
|
|
|
|
}
|