2009-07-09 08:18:58 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* 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.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\ORM\Query;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is used to generate DQL expressions via a set of PHP static functions
|
|
|
|
*
|
|
|
|
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link http://www.phpdoctrine.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
|
|
|
class Expr
|
|
|
|
{
|
2009-07-10 21:53:48 +04:00
|
|
|
public static function andx($x = null)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Andx(func_get_args());
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 21:53:48 +04:00
|
|
|
public static function orx($x = null)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Orx(func_get_args());
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 21:53:48 +04:00
|
|
|
public static function select($select = null)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Select(func_get_args());
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
2009-08-15 00:46:43 +04:00
|
|
|
|
|
|
|
public static function from($from, $alias = null)
|
|
|
|
{
|
|
|
|
return new Expr\From($from, $alias);
|
|
|
|
}
|
2009-08-15 02:50:36 +04:00
|
|
|
|
|
|
|
public static function join($joinType, $join, $alias = null, $conditionType = null, $condition = null)
|
|
|
|
{
|
|
|
|
return new Expr\Join($joinType, $join, $alias, $conditionType, $condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function leftJoin($join, $alias = null, $conditionType = null, $condition = null)
|
|
|
|
{
|
|
|
|
return new Expr\Join(Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function innerJoin($join, $alias = null, $conditionType = null, $condition = null)
|
|
|
|
{
|
|
|
|
return new Expr\Join(Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition);
|
|
|
|
}
|
2009-07-09 08:18:58 +04:00
|
|
|
|
2009-07-10 21:53:48 +04:00
|
|
|
public static function orderBy($sort = null, $order = null)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 21:53:48 +04:00
|
|
|
return new Expr\OrderBy($sort, $order);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function groupBy($groupBy = null)
|
|
|
|
{
|
|
|
|
return new Expr\GroupBy(func_get_args());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function having($having = null)
|
|
|
|
{
|
|
|
|
return new Expr\Having(func_get_args());
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function eq($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '=', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function neq($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '<>', $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function lt($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '<', $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function lte($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '<=', $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function gt($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '>', $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function gte($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Comparison($x, '>=', $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-07-09 08:18:58 +04:00
|
|
|
public static function avg($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('AVG', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function max($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('MAX', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function min($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('MIN', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function count($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('COUNT', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 00:46:43 +04:00
|
|
|
public static function countDistinct($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 21:53:48 +04:00
|
|
|
return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')';
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function exists($subquery)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('EXISTS', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function all($subquery)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ALL', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function some($subquery)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('SOME', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function any($subquery)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ANY', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function not($restriction)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('NOT', array($restriction));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function abs($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ABS', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function prod($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '*', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function diff($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '-', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function sum($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '+', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function quot($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '/', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function sqrt($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('SQRT', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function in($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func($x . ' IN', (array) $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function notIn($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func($x . ' NOT IN', (array) $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function like($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-08-15 00:46:43 +04:00
|
|
|
return new Expr\Comparison($x, 'LIKE', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function concat($x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('CONCAT', array($x, $y));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-07-10 18:02:06 +04:00
|
|
|
public static function substr($x, $from, $len)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('SUBSTR', array($x, $from, $len));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function lower($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('LOWER', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function upper($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('UPPER', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function length($x)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('LENGTH', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function literal($literal)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
if (is_numeric($literal)) {
|
|
|
|
return (string) $literal;
|
|
|
|
} else {
|
|
|
|
return "'" . $literal . "'";
|
|
|
|
}
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function between($val, $x, $y)
|
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('BETWEEN', array($val, $x, $y));
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 00:46:43 +04:00
|
|
|
public static function trim($x)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-15 00:46:43 +04:00
|
|
|
return new Expr\Func('TRIM', $x);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|