Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
312d347d
Commit
312d347d
authored
Jul 10, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] More work on the QueryBuilder and Expr classes
parent
838768d2
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
698 additions
and
459 deletions
+698
-459
EntityManager.php
lib/Doctrine/ORM/EntityManager.php
+1
-1
Expr.php
lib/Doctrine/ORM/Query/Expr.php
+56
-367
Andx.php
lib/Doctrine/ORM/Query/Expr/Andx.php
+42
-0
Base.php
lib/Doctrine/ORM/Query/Expr/Base.php
+75
-0
Comparison.php
lib/Doctrine/ORM/Query/Expr/Comparison.php
+50
-0
CountDistinctFunction.php
lib/Doctrine/ORM/Query/Expr/CountDistinctFunction.php
+46
-0
Func.php
lib/Doctrine/ORM/Query/Expr/Func.php
+48
-0
Math.php
lib/Doctrine/ORM/Query/Expr/Math.php
+50
-0
Orx.php
lib/Doctrine/ORM/Query/Expr/Orx.php
+42
-0
Select.php
lib/Doctrine/ORM/Query/Expr/Select.php
+41
-0
SelectField.php
lib/Doctrine/ORM/Query/Expr/SelectField.php
+49
-0
QueryBuilder.php
lib/Doctrine/ORM/QueryBuilder.php
+71
-24
ExprTest.php
tests/Doctrine/Tests/ORM/Query/ExprTest.php
+27
-45
QueryBuilderTest.php
tests/Doctrine/Tests/ORM/QueryBuilderTest.php
+100
-22
No files found.
lib/Doctrine/ORM/EntityManager.php
View file @
312d347d
...
...
@@ -226,7 +226,7 @@ class EntityManager
}
return
$query
;
}
/**
* Creates a DQL query with the specified name.
*
...
...
lib/Doctrine/ORM/Query/Expr.php
View file @
312d347d
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Query/Expr/Andx.php
0 → 100644
View file @
312d347d
<?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 building and clauses
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class
Andx
extends
Base
{
protected
$_separator
=
') AND ('
;
protected
$_allowedClasses
=
array
(
'Doctrine\ORM\Query\Expr\Comparison'
,
'Doctrine\ORM\Query\Expr\Orx'
,
'Doctrine\ORM\Query\Expr\Func'
);
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Base.php
0 → 100644
View file @
312d347d
<?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
;
/**
* Abstract class for building DQL expressions
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
abstract
class
Base
{
protected
$_preSeparator
=
'('
;
protected
$_separator
=
', '
;
protected
$_postSeparator
=
')'
;
protected
$_allowedClasses
=
array
();
private
$_parts
=
array
();
public
function
__construct
(
$args
=
array
())
{
foreach
(
$args
as
$arg
)
{
$this
->
add
(
$arg
);
}
}
public
function
add
(
$arg
)
{
if
(
!
empty
(
$arg
)
||
(
$arg
instanceof
self
&&
$arg
->
count
()
>
0
))
{
// If we decide to keep Expr\Base instances, we can use this check
if
(
!
is_string
(
$arg
))
{
$class
=
get_class
(
$arg
);
if
(
!
in_array
(
$class
,
$this
->
_allowedClasses
))
{
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
"Class '
{
$class
}
' is not allowed in "
.
get_class
(
$this
)
.
" instance."
);
}
}
$this
->
_parts
[]
=
$arg
;
}
}
public
function
count
()
{
return
count
(
$this
->
_parts
);
}
public
function
__tostring
()
{
return
$this
->
_preSeparator
.
implode
(
$this
->
_separator
,
$this
->
_parts
)
.
$this
->
_postSeparator
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Comparison.php
0 → 100644
View file @
312d347d
<?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 comparison statements
*
* @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
Comparison
{
private
$_leftExpr
;
private
$_operator
;
private
$_rightExpr
;
public
function
__construct
(
$leftExpr
,
$operator
,
$rightExpr
)
{
$this
->
_leftExpr
=
$leftExpr
;
$this
->
_operator
=
$operator
;
$this
->
_rightExpr
=
$rightExpr
;
}
public
function
__toString
()
{
return
$this
->
_leftExpr
.
' '
.
$this
->
_operator
.
' '
.
$this
->
_rightExpr
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/CountDistinctFunction.php
0 → 100644
View file @
312d347d
<?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 building comparison clauses
*
* @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
CountDistinctFunction
{
private
$_arguments
;
public
function
__construct
(
$arguments
)
{
$this
->
_arguments
=
$arguments
;
}
public
function
__toString
()
{
return
'COUNT(DISTINCT '
.
implode
(
', '
,
$this
->
_arguments
)
.
')'
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Func.php
0 → 100644
View file @
312d347d
<?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 building comparison clauses
*
* @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
Func
{
private
$_name
;
private
$_arguments
;
public
function
__construct
(
$name
,
$arguments
)
{
$this
->
_name
=
$name
;
$this
->
_arguments
=
$arguments
;
}
public
function
__toString
()
{
return
$this
->
_name
.
'('
.
implode
(
', '
,
$this
->
_arguments
)
.
')'
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Math.php
0 → 100644
View file @
312d347d
<?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 math statements
*
* @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
Math
{
private
$_leftExpr
;
private
$_operator
;
private
$_rightExpr
;
public
function
__construct
(
$leftExpr
,
$operator
,
$rightExpr
)
{
$this
->
_leftExpr
=
$leftExpr
;
$this
->
_operator
=
$operator
;
$this
->
_rightExpr
=
$rightExpr
;
}
public
function
__toString
()
{
return
$this
->
_leftExpr
.
' '
.
$this
->
_operator
.
' '
.
$this
->
_rightExpr
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Orx.php
0 → 100644
View file @
312d347d
<?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 building and clauses
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class
Orx
extends
Base
{
protected
$_separator
=
') OR ('
;
protected
$_allowedClasses
=
array
(
'Doctrine\ORM\Query\Expr\Comparison'
,
'Doctrine\ORM\Query\Expr\Andx'
,
'Doctrine\ORM\Query\Expr\Func'
);
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/Select.php
0 → 100644
View file @
312d347d
<?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 building DQL select clauses
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class
Select
extends
Base
{
protected
$_preSeparator
=
''
;
protected
$_postSeparator
=
''
;
protected
$_allowedClasses
=
array
(
'Doctrine\ORM\Query\Expr\SelectField'
);
}
\ No newline at end of file
lib/Doctrine/ORM/Query/Expr/SelectField.php
0 → 100644
View file @
312d347d
<?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
;
/**
* This class is used for representing field in a select statement
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class
SelectField
{
private
$_field
;
private
$_alias
;
public
function
__construct
(
$field
,
$alias
=
null
)
{
$this
->
_field
=
$field
;
$this
->
_alias
=
$alias
;
}
public
function
__toString
()
{
return
$this
->
_field
.
((
$this
->
_alias
!==
null
)
?
' AS '
.
$this
->
_alias
:
''
);
}
}
\ No newline at end of file
lib/Doctrine/ORM/QueryBuilder.php
View file @
312d347d
...
...
@@ -224,7 +224,7 @@ class QueryBuilder
return
$this
;
}
public
function
select
()
public
function
select
(
$select
)
{
$selects
=
func_get_args
();
$this
->
_type
=
self
::
SELECT
;
...
...
@@ -233,7 +233,8 @@ class QueryBuilder
return
$this
;
}
return
$this
->
add
(
'select'
,
implode
(
', '
,
$selects
),
true
);
$select
=
call_user_func_array
(
array
(
'Doctrine\ORM\Query\Expr'
,
'select'
),
$selects
);
return
$this
->
add
(
'select'
,
$select
,
true
);
}
public
function
delete
(
$delete
=
null
,
$alias
=
null
)
...
...
@@ -244,7 +245,7 @@ class QueryBuilder
return
$this
;
}
return
$this
->
add
(
'from'
,
Expr
::
from
(
$delete
,
$alias
)
);
return
$this
->
add
(
'from'
,
$delete
.
' '
.
$alias
);
}
public
function
update
(
$update
=
null
,
$alias
=
null
)
...
...
@@ -255,7 +256,7 @@ class QueryBuilder
return
$this
;
}
return
$this
->
add
(
'from'
,
Expr
::
from
(
$update
,
$alias
)
);
return
$this
->
add
(
'from'
,
$update
.
' '
.
$alias
);
}
public
function
set
(
$key
,
$value
)
...
...
@@ -265,24 +266,87 @@ class QueryBuilder
public
function
from
(
$from
,
$alias
)
{
return
$this
->
add
(
'from'
,
Expr
::
from
(
$from
,
$alias
)
,
true
);
return
$this
->
add
(
'from'
,
$from
.
' '
.
$alias
,
true
);
}
public
function
innerJoin
(
$parentAlias
,
$join
,
$alias
,
$condition
=
null
)
{
return
$this
->
add
(
'from'
,
Expr
::
innerJoin
(
$parentAlias
,
$join
,
$alias
,
$condition
),
true
);
$join
=
'INNER JOIN '
.
$parentAlias
.
'.'
.
$join
.
' '
.
$alias
.
(
isset
(
$condition
)
?
' '
.
$condition
:
null
);
return
$this
->
add
(
'from'
,
$join
,
true
);
}
public
function
leftJoin
(
$parentAlias
,
$join
,
$alias
,
$condition
=
null
)
{
return
$this
->
add
(
'from'
,
Expr
::
leftJoin
(
$parentAlias
,
$join
,
$alias
,
$condition
),
true
);
$join
=
'LEFT JOIN '
.
$parentAlias
.
'.'
.
$join
.
' '
.
$alias
.
(
isset
(
$condition
)
?
' '
.
$condition
:
null
);
return
$this
->
add
(
'from'
,
$join
,
true
);
}
public
function
where
(
$where
)
{
$where
=
call_user_func_array
(
array
(
'Doctrine\ORM\Query\Expr'
,
'andx'
),
func_get_args
());
return
$this
->
add
(
'where'
,
$where
,
false
);
}
public
function
andWhere
(
$where
)
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'AND'
,
true
);
}
$where
=
call_user_func_array
(
array
(
'Doctrine\ORM\Query\Expr'
,
'andx'
),
func_get_args
());
return
$this
->
add
(
'where'
,
$where
,
true
);
}
public
function
orWhere
(
$where
)
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'OR'
,
true
);
}
$where
=
call_user_func_array
(
array
(
'Doctrine\ORM\Query\Expr'
,
'orx'
),
func_get_args
());
return
$this
->
add
(
'where'
,
$where
,
true
);
}
public
function
andWhereIn
(
$expr
,
$params
)
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'AND'
,
true
);
}
return
$this
->
add
(
'where'
,
Expr
::
in
(
$expr
,
$params
),
true
);
}
public
function
orWhereIn
(
$expr
,
$params
=
array
(),
$not
=
false
)
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'OR'
,
true
);
}
return
$this
->
add
(
'where'
,
Expr
::
in
(
$expr
,
$params
),
true
);
}
public
function
andWhereNotIn
(
$expr
,
$params
=
array
())
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'AND'
,
true
);
}
return
$this
->
add
(
'where'
,
Expr
::
notIn
(
$expr
,
$params
),
true
);
}
public
function
orWhereNotIn
(
$expr
,
$params
=
array
())
{
if
(
count
(
$this
->
_getDqlQueryPart
(
'where'
))
>
0
)
{
$this
->
add
(
'where'
,
'OR'
,
true
);
}
return
$this
->
add
(
'where'
,
Expr
::
notIn
(
$expr
,
$params
),
true
);
}
public
function
groupBy
(
$groupBy
)
{
return
$this
->
add
(
'groupBy'
,
$groupBy
,
false
);
...
...
@@ -427,21 +491,4 @@ class QueryBuilder
{
return
$this
->
_dqlParts
[
$queryPartName
];
}
/**
* Proxy method calls to the Expr class to ease the syntax of the query builder
*
* @param string $method The method name called
* @param string $arguments The arguments passed to the method
* @return void
* @throws \Doctrine\Common\DoctrineException Throws exception if method could not be proxied
*/
public
function
__call
(
$method
,
$arguments
)
{
$class
=
'Doctrine\ORM\Query\Expr'
;
if
(
method_exists
(
$class
,
$method
))
{
return
call_user_func_array
(
array
(
'Doctrine\ORM\Query\Expr'
,
$method
),
$arguments
);
}
throw
\Doctrine\Common\DoctrineException
::
notImplemented
(
$method
,
get_class
(
$this
));
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Query/ExprTest.php
View file @
312d347d
...
...
@@ -97,12 +97,12 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public
function
testAndExpr
()
{
$this
->
assertEquals
(
'(1 = 1
AND
2 = 2)'
,
(
string
)
Expr
::
andx
((
string
)
Expr
::
eq
(
1
,
1
),
(
string
)
Expr
::
eq
(
2
,
2
)));
$this
->
assertEquals
(
'(1 = 1
) AND (
2 = 2)'
,
(
string
)
Expr
::
andx
((
string
)
Expr
::
eq
(
1
,
1
),
(
string
)
Expr
::
eq
(
2
,
2
)));
}
public
function
testOrExpr
()
{
$this
->
assertEquals
(
'(1 = 1
OR
2 = 2)'
,
(
string
)
Expr
::
orx
((
string
)
Expr
::
eq
(
1
,
1
),
(
string
)
Expr
::
eq
(
2
,
2
)));
$this
->
assertEquals
(
'(1 = 1
) OR (
2 = 2)'
,
(
string
)
Expr
::
orx
((
string
)
Expr
::
eq
(
1
,
1
),
(
string
)
Expr
::
eq
(
2
,
2
)));
}
public
function
testAbsExpr
()
...
...
@@ -112,22 +112,22 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public
function
testProdExpr
()
{
$this
->
assertEquals
(
'
(1 * 2)
'
,
(
string
)
Expr
::
prod
(
1
,
2
));
$this
->
assertEquals
(
'
1 * 2
'
,
(
string
)
Expr
::
prod
(
1
,
2
));
}
public
function
testDiffExpr
()
{
$this
->
assertEquals
(
'
(1 - 2)
'
,
(
string
)
Expr
::
diff
(
1
,
2
));
$this
->
assertEquals
(
'
1 - 2
'
,
(
string
)
Expr
::
diff
(
1
,
2
));
}
public
function
testSumExpr
()
{
$this
->
assertEquals
(
'
(1 + 2)
'
,
(
string
)
Expr
::
sum
(
1
,
2
));
$this
->
assertEquals
(
'
1 + 2
'
,
(
string
)
Expr
::
sum
(
1
,
2
));
}
public
function
testQuotientExpr
()
{
$this
->
assertEquals
(
'
(10 / 2)
'
,
(
string
)
Expr
::
quot
(
10
,
2
));
$this
->
assertEquals
(
'
10 / 2
'
,
(
string
)
Expr
::
quot
(
10
,
2
));
}
public
function
testSquareRootExpr
()
...
...
@@ -147,7 +147,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public
function
testLikeExpr
()
{
$this
->
assertEquals
(
'
(a.description LIKE :description)
'
,
(
string
)
Expr
::
like
(
'a.description'
,
':description'
));
$this
->
assertEquals
(
'
a.description LIKE :description
'
,
(
string
)
Expr
::
like
(
'a.description'
,
':description'
));
}
public
function
testConcatExpr
()
...
...
@@ -178,18 +178,11 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public
function
testGreaterThanExpr
()
{
$this
->
assertEquals
(
'5 > 2'
,
(
string
)
Expr
::
gt
(
5
,
2
));
$this
->
assertEquals
(
'5 > 2'
,
(
string
)
Expr
::
greaterThan
(
5
,
2
));
}
public
function
testLessThanExpr
()
{
$this
->
assertEquals
(
'2 < 5'
,
(
string
)
Expr
::
lt
(
2
,
5
));
$this
->
assertEquals
(
'2 < 5'
,
(
string
)
Expr
::
lessThan
(
2
,
5
));
}
public
function
testPathExpr
()
{
// TODO: This functionality still needs to be written and tested
}
public
function
testStringLiteralExpr
()
...
...
@@ -204,14 +197,12 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public
function
testGreaterThanOrEqualToExpr
()
{
$this
->
assertEquals
(
'5 >= 2'
,
(
string
)
Expr
::
gtoet
(
5
,
2
));
$this
->
assertEquals
(
'5 >= 2'
,
(
string
)
Expr
::
greaterThanOrEqualTo
(
5
,
2
));
$this
->
assertEquals
(
'5 >= 2'
,
(
string
)
Expr
::
gte
(
5
,
2
));
}
public
function
testLessThanOrEqualTo
()
{
$this
->
assertEquals
(
'2 <= 5'
,
(
string
)
Expr
::
ltoet
(
2
,
5
));
$this
->
assertEquals
(
'2 <= 5'
,
(
string
)
Expr
::
lessThanOrEqualTo
(
2
,
5
));
$this
->
assertEquals
(
'2 <= 5'
,
(
string
)
Expr
::
lte
(
2
,
5
));
}
public
function
testBetweenExpr
()
...
...
@@ -229,43 +220,34 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertEquals
(
'u.id IN(1, 2, 3)'
,
(
string
)
Expr
::
in
(
'u.id'
,
array
(
1
,
2
,
3
)));
}
public
function
test
On
Expr
()
public
function
test
AndxOrx
Expr
()
{
$this
->
assertEquals
(
'ON 1 = 1'
,
(
string
)
Expr
::
on
(
Expr
::
eq
(
1
,
1
)));
}
public
function
testWithExpr
()
{
$this
->
assertEquals
(
'WITH 1 = 1'
,
(
string
)
Expr
::
with
(
Expr
::
eq
(
1
,
1
)));
}
$andExpr
=
Expr
::
andx
();
$andExpr
->
add
(
Expr
::
eq
(
1
,
1
));
$andExpr
->
add
(
Expr
::
lt
(
1
,
5
));
public
function
testLeftJoinExpr
()
{
$this
->
assertEquals
(
'LEFT JOIN u.Profile p'
,
(
string
)
Expr
::
leftJoin
(
'u'
,
'Profile'
,
'p'
));
}
$orExpr
=
Expr
::
orx
();
$orExpr
->
add
(
$andExpr
);
$orExpr
->
add
(
Expr
::
eq
(
1
,
1
));
public
function
testLeftJoinOnConditionExpr
()
{
$this
->
assertEquals
(
'LEFT JOIN u.Profile p ON p.user_id = u.id'
,
(
string
)
Expr
::
leftJoin
(
'u'
,
'Profile'
,
'p'
,
Expr
::
on
(
Expr
::
eq
(
'p.user_id'
,
'u.id'
))));
$this
->
assertEquals
(
'((1 = 1) AND (1 < 5)) OR (1 = 1)'
,
(
string
)
$orExpr
);
}
public
function
test
LeftJoinWithCondition
Expr
()
public
function
test
Orx
Expr
()
{
$this
->
assertEquals
(
'LEFT JOIN u.Profile p WITH p.user_id = u.id'
,
(
string
)
Expr
::
leftJoin
(
'u'
,
'Profile'
,
'p'
,
Expr
::
with
(
Expr
::
eq
(
'p.user_id'
,
'u.id'
))));
}
$orExpr
=
Expr
::
orx
();
$orExpr
->
add
(
Expr
::
eq
(
1
,
1
));
$orExpr
->
add
(
Expr
::
lt
(
1
,
5
));
public
function
testInnerJoinExpr
()
{
$this
->
assertEquals
(
'INNER JOIN u.Profile p'
,
(
string
)
Expr
::
innerJoin
(
'u'
,
'Profile'
,
'p'
));
$this
->
assertEquals
(
'(1 = 1) OR (1 < 5)'
,
(
string
)
$orExpr
);
}
public
function
test
InnerJoinOnCondition
Expr
()
public
function
test
Select
Expr
()
{
$this
->
assertEquals
(
'INNER JOIN u.Profile p ON p.user_id = u.id'
,
(
string
)
Expr
::
innerJoin
(
'u'
,
'Profile'
,
'p'
,
Expr
::
on
(
Expr
::
eq
(
'p.user_id'
,
'u.id'
))));
}
$selectExpr
=
Expr
::
select
();
$selectExpr
->
add
(
Expr
::
selectField
(
'u.id'
));
$selectExpr
->
add
(
Expr
::
selectField
(
'u.username'
,
'my_test'
));
public
function
testInnerJoinWithConditionExpr
()
{
$this
->
assertEquals
(
'INNER JOIN u.Profile p WITH p.user_id = u.id'
,
(
string
)
Expr
::
innerJoin
(
'u'
,
'Profile'
,
'p'
,
Expr
::
with
(
Expr
::
eq
(
'p.user_id'
,
'u.id'
))));
$this
->
assertEquals
(
'u.id, u.username AS my_test'
,
(
string
)
$selectExpr
);
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/QueryBuilderTest.php
View file @
312d347d
...
...
@@ -52,17 +52,6 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
{
$dql
=
$qb
->
getDql
();
$q
=
$qb
->
getQuery
();
//FIXME: QueryBuilder tests should not test the Parser or SQL building, so
// this block should probably be removed.
try
{
$q
->
getSql
();
}
catch
(
\Exception
$e
)
{
echo
$dql
.
"
\n
"
;
echo
$e
->
getTraceAsString
();
$this
->
fail
(
$e
->
getMessage
());
}
//--
$this
->
assertEquals
(
$expectedDql
,
$dql
);
}
...
...
@@ -147,7 +136,73 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = :uid'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid)'
);
}
public
function
testAndWhere
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhere
(
'u.id = :uid2'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id = :uid2)'
);
}
public
function
testOrWhere
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
orWhere
(
'u.id = :uid2'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id = :uid2)'
);
}
public
function
testAndWhereIn
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhereIn
(
'u.id'
,
array
(
1
,
2
,
3
));
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND u.id IN(1, 2, 3)'
);
}
public
function
testOrWhereIn
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
orWhereIn
(
'u.id'
,
array
(
1
,
2
,
3
));
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR u.id IN(1, 2, 3)'
);
}
public
function
testAndWhereNotIn
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhereNotIn
(
'u.id'
,
array
(
1
,
2
,
3
));
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND u.id NOT IN(1, 2, 3)'
);
}
public
function
testOrWhereNotIn
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
OrWhereNotIn
(
'u.id'
,
array
(
1
,
2
,
3
));
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR u.id NOT IN(1, 2, 3)'
);
}
public
function
testGroupBy
()
...
...
@@ -254,25 +309,48 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertEquals
(
$q
->
getParameters
(),
array
(
'username'
=>
'jwage'
,
'username2'
=>
'jonwage'
));
}
public
function
test
ExprProxyWithMagicCall
()
public
function
test
MultipleWhere
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
;
$qb
->
where
(
$qb
->
eq
(
'u.id'
,
1
)
);
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
,
'u.id = :uid2'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE
u.id = 1
'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE
(u.id = :uid) AND (u.id = :uid2)
'
);
}
/**
* @expectedException \Doctrine\Common\DoctrineException
*/
public
function
testInvalidQueryBuilderMethodThrowsException
()
public
function
testMultipleAndWhere
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
);
$qb
->
where
(
$qb
->
blah
(
'u.id'
,
1
));
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
andWhere
(
'u.id = :uid'
,
'u.id = :uid2'
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id = :uid2)'
);
}
public
function
testMultipleOrWhere
()
{
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
orWhere
(
'u.id = :uid'
,
Expr
::
eq
(
'u.id'
,
':uid2'
));
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id = :uid2)'
);
}
public
function
testComplexWhere
()
{
$orExpr
=
Expr
::
orx
();
$orExpr
->
add
(
Expr
::
eq
(
'u.id'
,
':uid3'
));
$orExpr
->
add
(
Expr
::
in
(
'u.id'
,
array
(
1
)));
$qb
=
QueryBuilder
::
create
(
$this
->
_em
)
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
$orExpr
);
$this
->
assertValidQueryBuilder
(
$qb
,
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id = :uid3) OR (u.id IN(1)))'
);
}
public
function
testLimit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment