[2.0] Some fixes in Expr. More documentation added.
This commit is contained in:
parent
abc853ec48
commit
c81affb9f7
@ -47,6 +47,11 @@ class Expr
|
||||
{
|
||||
return new Expr\Select(func_get_args());
|
||||
}
|
||||
|
||||
public static function from($from, $alias = null)
|
||||
{
|
||||
return new Expr\From($from, $alias);
|
||||
}
|
||||
|
||||
public static function orderBy($sort = null, $order = null)
|
||||
{
|
||||
@ -113,7 +118,7 @@ class Expr
|
||||
return new Expr\Func('COUNT', array($x));
|
||||
}
|
||||
|
||||
public static function countDistinct()
|
||||
public static function countDistinct($x)
|
||||
{
|
||||
return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')';
|
||||
}
|
||||
@ -183,14 +188,9 @@ class Expr
|
||||
return new Expr\Func($x . ' NOT IN', (array) $y);
|
||||
}
|
||||
|
||||
public static function notEqual($x, $y)
|
||||
{
|
||||
return new Expr\Comparison($x, '!=', $y);
|
||||
}
|
||||
|
||||
public static function like($x, $y)
|
||||
{
|
||||
return new Expr\Math($x, 'LIKE', $y);
|
||||
return new Expr\Comparison($x, 'LIKE', $y);
|
||||
}
|
||||
|
||||
public static function concat($x, $y)
|
||||
@ -232,8 +232,8 @@ class Expr
|
||||
return new Expr\Func('BETWEEN', array($val, $x, $y));
|
||||
}
|
||||
|
||||
public static function trim()
|
||||
public static function trim($x)
|
||||
{
|
||||
return new Expr\Func('TRIM', func_get_args());
|
||||
return new Expr\Func('TRIM', $x);
|
||||
}
|
||||
}
|
48
lib/Doctrine/ORM/Query/Expr/From.php
Normal file
48
lib/Doctrine/ORM/Query/Expr/From.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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\Expr;
|
||||
|
||||
/**
|
||||
* Expression class for DQL from
|
||||
*
|
||||
* @author Jonathan H. Wage <jonwage@gmail.com>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link http://www.phpdoctrine.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class From
|
||||
{
|
||||
private $_from;
|
||||
private $_alias;
|
||||
|
||||
public function __construct($from, $alias = null)
|
||||
{
|
||||
$this->_from = $from;
|
||||
$this->_alias = $alias;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_from . ($this->_alias ? ' ' . $this->_alias : '');
|
||||
}
|
||||
}
|
@ -37,8 +37,8 @@ class Func
|
||||
|
||||
public function __construct($name, $arguments)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_arguments = $arguments;
|
||||
$this->_name = $name;
|
||||
$this->_arguments = (array) $arguments;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
@ -252,9 +252,9 @@ class QueryBuilder
|
||||
return $this->add('set', Expr::eq($key, $value), true);
|
||||
}
|
||||
|
||||
public function from($from, $alias)
|
||||
public function from($from, $alias = null)
|
||||
{
|
||||
return $this->add('from', $from . ' ' . $alias, true);
|
||||
return $this->add('from', Expr::from($from, $alias), true);
|
||||
}
|
||||
|
||||
public function innerJoin($parentAlias, $join, $alias, $condition = null)
|
||||
|
@ -140,11 +140,6 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
|
||||
$this->assertEquals('1 = 1', (string) Expr::eq(1, 1));
|
||||
}
|
||||
|
||||
public function testNotEqualExpr()
|
||||
{
|
||||
$this->assertEquals('1 != 2', (string) Expr::notEqual(1, 2));
|
||||
}
|
||||
|
||||
public function testLikeExpr()
|
||||
{
|
||||
$this->assertEquals('a.description LIKE :description', (string) Expr::like('a.description', ':description'));
|
||||
|
Loading…
Reference in New Issue
Block a user