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
|
|
|
|
*
|
2009-09-06 00:05:39 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision$
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2009-07-09 08:18:58 +04:00
|
|
|
*/
|
|
|
|
class Expr
|
|
|
|
{
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Andx with given arguments.
|
|
|
|
* Each argument is separated by an "AND". Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // (u.type = ?1) AND (u.role = ?2)
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->andx('u.type = ?1', 'u.role = ?2'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Optional clause. Defaults = null, but requires
|
|
|
|
* at least one defined when converting to string.
|
|
|
|
* @return Expr\Andx
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Orx with given arguments.
|
|
|
|
* Each argument is separated by an "OR". Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // (u.type = ?1) OR (u.role = ?2)
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->orx('u.type = ?1', 'u.role = ?2'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Optional clause. Defaults = null, but requires
|
|
|
|
* at least one defined when converting to string.
|
|
|
|
* @return Expr\Orx
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Select with given arguments.
|
|
|
|
* Each argument is separated by a ",". Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id, u.name, u.surname
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->select($q->expr()->select('u.id', 'u.name')->add('u.surname'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $select Optional select. Defaults = null, but requires
|
|
|
|
* at least one defined when converting to string.
|
|
|
|
* @return Expr\Select
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\From with given arguments.
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // User u
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->from($q->expr()->from('User', 'u'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param string $from Entity name.
|
|
|
|
* @param string $alias Optional alias to be used by Entity.
|
|
|
|
* @return Expr\From
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function from($from, $alias = null)
|
2009-08-15 00:46:43 +04:00
|
|
|
{
|
|
|
|
return new Expr\From($from, $alias);
|
|
|
|
}
|
2009-08-15 02:50:36 +04:00
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Join with given arguments.
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // LEFT JOIN u.Group g WITH g.name = 'admin'
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->leftJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param string $join Relation join.
|
|
|
|
* @param string $alias Optional alias to be used by Relation.
|
|
|
|
* @param string $conditionType Optional type of condition appender. Accepts either string or constant.
|
|
|
|
* 'ON' and 'WITH' are supported strings. Expr\Join::ON and Expr\Join::WITH are supported constants.
|
|
|
|
* @param mixed $condition Optional condition to be appended.
|
|
|
|
* @return Expr\Join
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function leftJoin($join, $alias = null, $conditionType = null, $condition = null)
|
2009-08-15 02:50:36 +04:00
|
|
|
{
|
|
|
|
return new Expr\Join(Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition);
|
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Join with given arguments.
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // INNER JOIN u.Group g WITH g.name = 'admin'
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->innerJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param string $join Relation join.
|
|
|
|
* @param string $alias Optional alias to be used by Relation.
|
|
|
|
* @param string $conditionType Optional type of condition appender. Accepts either string or constant.
|
|
|
|
* 'ON' and 'WITH' are supported strings. Expr\Join::ON and Expr\Join::WITH are supported constants.
|
|
|
|
* @param mixed $condition Optional condition to be appended.
|
|
|
|
* @return Expr\Join
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function innerJoin($join, $alias = null, $conditionType = null, $condition = null)
|
2009-08-15 02:50:36 +04:00
|
|
|
{
|
|
|
|
return new Expr\Join(Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition);
|
|
|
|
}
|
2009-07-09 08:18:58 +04:00
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\OrderBy with given item sort and order.
|
|
|
|
* Each argument is separated by a ",". Example:
|
|
|
|
*
|
|
|
|
* [php]
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->orderBy($q->expr()->orderBy('u.surname', 'ASC')->add('u.name', 'ASC'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param string $sort Optional item sort.
|
|
|
|
* @param string $order Optional order to be applied in item.
|
|
|
|
* @return Expr\OrderBy
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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);
|
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\GroupBy with given arguments.
|
|
|
|
* Each argument is separated by a ",". Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id, u.name
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->select($q->expr()->groupBy('u.id', 'u.name'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $groupBy Optional group by. Defaults = null, but requires
|
|
|
|
* at least one defined when converting to string.
|
|
|
|
* @return Expr\Select
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function groupBy($groupBy = null)
|
2009-07-10 21:53:48 +04:00
|
|
|
{
|
|
|
|
return new Expr\GroupBy(func_get_args());
|
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> = <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id = ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->eq('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function eq($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::EQ, $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> <> <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id <> ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->neq('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function neq($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::NEQ, $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> < <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id < ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->lt('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function lt($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::LT, $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> <= <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id <= ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->lte('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function lte($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::LTE, $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> > <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id > ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->gt('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function gt($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::GT, $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of Expr\Comparison, with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> >= <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.id >= ?1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->where($q->expr()->gte('u.id', '?1'));
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function gte($x, $y)
|
2009-07-10 01:56:34 +04:00
|
|
|
{
|
2009-08-20 06:59:42 +04:00
|
|
|
return new Expr\Comparison($x, Expr\Comparison::GTE, $y);
|
2009-07-10 01:56:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of AVG() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in AVG() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function avg($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('AVG', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of MAX() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in MAX() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function max($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('MAX', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of MIN() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in MIN() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function min($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('MIN', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of COUNT() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in COUNT() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function count($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('COUNT', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of COUNT(DISTINCT) function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in COUNT(DISTINCT) function.
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of EXISTS() function, with the given DQL Subquery.
|
|
|
|
*
|
|
|
|
* @param mixed $subquery DQL Subquery to be used in EXISTS() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function exists($subquery)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('EXISTS', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of ALL() function, with the given DQL Subquery.
|
|
|
|
*
|
|
|
|
* @param mixed $subquery DQL Subquery to be used in ALL() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function all($subquery)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ALL', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of SOME() function, with the given DQL Subquery.
|
|
|
|
*
|
|
|
|
* @param mixed $subquery DQL Subquery to be used in SOME() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function some($subquery)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('SOME', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of ANY() function, with the given DQL subquery.
|
|
|
|
*
|
|
|
|
* @param mixed $subquery DQL Subquery to be used in ANY() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function any($subquery)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ANY', array($subquery));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of NOT() function, with the given restriction.
|
|
|
|
*
|
|
|
|
* @param mixed $restriction Restriction to be used in NOT() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function not($restriction)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('NOT', array($restriction));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of ABS() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in ABS() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function abs($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('ABS', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a product mathematical expression with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> * <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.salary * u.percentAnualSalaryIncrease
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->prod('u.salary', 'u.percentAnualSalaryIncrease')
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Math
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function prod($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '*', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a difference mathematical expression with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> - <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.monthlySubscriptionCount - 1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->diff('u.monthlySubscriptionCount', '1')
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Math
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function diff($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '-', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a sum mathematical expression with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> + <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.numChildren + 1
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->diff('u.numChildren', '1')
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Math
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function sum($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '+', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a quotient mathematical expression with the given arguments.
|
|
|
|
* First argument is considered the left expression and the second is the right expression.
|
|
|
|
* When converted to string, it will generated a <left expr> / <right expr>. Example:
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* // u.total - u.period
|
2009-09-09 02:19:03 +04:00
|
|
|
* $q->expr()->diff('u.total', 'u.period')
|
2009-09-06 00:05:39 +04:00
|
|
|
*
|
|
|
|
* @param mixed $x Left expression
|
|
|
|
* @param mixed $y Right expression
|
|
|
|
* @return Expr\Math
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function quot($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Math($x, '/', $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of SQRT() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in SQRT() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function sqrt($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('SQRT', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of field IN() function, with the given arguments.
|
|
|
|
*
|
|
|
|
* @param string $x Field in string format to be restricted by IN() function
|
|
|
|
* @param mixed $y Argument to be used in IN() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function in($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func($x . ' IN', (array) $y);
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of field NOT IN() function, with the given arguments.
|
|
|
|
*
|
|
|
|
* @param string $x Field in string format to be restricted by NOT IN() function
|
|
|
|
* @param mixed $y Argument to be used in NOT IN() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function notIn($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
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-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of field LIKE() comparison, with the given arguments.
|
|
|
|
*
|
|
|
|
* @param string $x Field in string format to be inspected by LIKE() comparison.
|
|
|
|
* @param mixed $y Argument to be used in LIKE() comparison.
|
|
|
|
* @return Expr\Comparison
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of CONCAT() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x First argument to be used in CONCAT() function.
|
|
|
|
* @param mixed $x Second argument to be used in CONCAT() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function concat($x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
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-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of SUBSTR() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used as string to be cropped by SUBSTR() function.
|
|
|
|
* @param integer $from Initial offset to start cropping string. May accept negative values.
|
|
|
|
* @param integer $len Length of crop. May accept negative values.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of LOWER() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in LOWER() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function lower($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('LOWER', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of LOWER() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used in LOWER() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function upper($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('UPPER', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of LENGTH() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used as argument of LENGTH() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function length($x)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
2009-07-10 18:02:06 +04:00
|
|
|
return new Expr\Func('LENGTH', array($x));
|
2009-07-09 08:18:58 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates a literal representation of the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $literal Argument to be converted to literal.
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function literal($literal)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2009-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of BETWEEN() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $val Valued to be inspected by range values.
|
|
|
|
* @param integer $x Starting range value to be used in BETWEEN() function.
|
|
|
|
* @param integer $y End point value to be used in BETWEEN() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public function between($val, $x, $y)
|
2009-07-09 08:18:58 +04:00
|
|
|
{
|
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-09-06 00:05:39 +04:00
|
|
|
/**
|
|
|
|
* Creates an instance of TRIM() function, with the given argument.
|
|
|
|
*
|
|
|
|
* @param mixed $x Argument to be used as argument of TRIM() function.
|
|
|
|
* @return Expr\Func
|
|
|
|
*/
|
2009-09-09 02:19:03 +04:00
|
|
|
public 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
|
|
|
}
|