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
d10daf35
Commit
d10daf35
authored
Sep 08, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Changing Expr static methods to be normal public methods (closes #2466)
parent
dbce89d7
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
153 deletions
+172
-153
Expr.php
lib/Doctrine/ORM/Query/Expr.php
+59
-59
QueryBuilder.php
lib/Doctrine/ORM/QueryBuilder.php
+19
-1
ExprTest.php
tests/Doctrine/Tests/ORM/Query/ExprTest.php
+55
-54
QueryBuilderTest.php
tests/Doctrine/Tests/ORM/QueryBuilderTest.php
+39
-39
No files found.
lib/Doctrine/ORM/Query/Expr.php
View file @
d10daf35
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/QueryBuilder.php
View file @
d10daf35
...
...
@@ -82,7 +82,12 @@ class QueryBuilder
* @var Query The Query instance used for this QueryBuilder.
*/
private
$_q
;
/**
* @var Expr The Expr instance used to generate DQL expressions
*/
private
$_expr
;
/**
* Initializes a new <tt>QueryBuilder</tt> that uses the given <tt>EntityManager</tt>.
*
...
...
@@ -94,6 +99,19 @@ class QueryBuilder
$this
->
_q
=
$entityManager
->
createQuery
();
}
/**
* Factory for instantiating and retrieving the Expr instance when needed
*
* @return Expr $expr
*/
public
function
expr
()
{
if
(
!
$this
->
_expr
)
{
$this
->
_expr
=
new
Expr
;
}
return
$this
->
_expr
;
}
public
function
getType
()
{
return
$this
->
_type
;
...
...
tests/Doctrine/Tests/ORM/Query/ExprTest.php
View file @
d10daf35
This diff is collapsed.
Click to expand it.
tests/Doctrine/Tests/ORM/QueryBuilderTest.php
View file @
d10daf35
...
...
@@ -183,44 +183,44 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public
function
testAndWhereIn
()
{
$qb
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhere
(
Expr
::
in
(
'u.id'
,
array
(
1
,
2
,
3
)));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhere
(
$qb
->
expr
()
->
in
(
'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
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
orWhere
(
Expr
::
in
(
'u.id'
,
array
(
1
,
2
,
3
)));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
orWhere
(
$qb
->
expr
()
->
in
(
'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
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhere
(
Expr
::
notIn
(
'u.id'
,
array
(
1
,
2
,
3
)));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
andWhere
(
$qb
->
expr
()
->
notIn
(
'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
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
OrWhere
(
Expr
::
notIn
(
'u.id'
,
array
(
1
,
2
,
3
)));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :uid'
)
->
orWhere
(
$qb
->
expr
()
->
notIn
(
'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))'
);
}
...
...
@@ -316,10 +316,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public
function
testSetParameters
()
{
$qb
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
Expr
::
orx
(
'u.username = :username'
,
'u.username = :username2'
));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
$qb
->
expr
()
->
orx
(
'u.username = :username'
,
'u.username = :username2'
));
$qb
->
setParameters
(
array
(
'username'
=>
'jwage'
,
'username2'
=>
'jonwage'
));
...
...
@@ -329,10 +329,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public
function
testGetParameters
()
{
$qb
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :id'
);
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
'u.id = :id'
);
$qb
->
setParameters
(
array
(
'id'
=>
1
));
$this
->
assertEquals
(
array
(
'id'
=>
1
,
'test'
=>
1
),
$qb
->
getParameters
(
array
(
'test'
=>
1
)));
...
...
@@ -371,24 +371,24 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public
function
testMultipleOrWhere
()
{
$qb
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
orWhere
(
'u.id = :uid'
,
Expr
::
eq
(
'u.id'
,
':uid2'
));
$qb
=
$this
->
_em
->
createQueryBuilder
()
;
$qb
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
orWhere
(
'u.id = :uid'
,
$qb
->
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
=
$this
->
_em
->
createQueryBuilder
();
$orExpr
=
$qb
->
expr
()
->
orx
();
$orExpr
->
add
(
$qb
->
expr
()
->
eq
(
'u.id'
,
':uid3'
));
$orExpr
->
add
(
$qb
->
expr
()
->
in
(
'u.id'
,
array
(
1
)));
$qb
=
$this
->
_em
->
createQueryBuilder
()
->
select
(
'u'
)
->
from
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
)
->
where
(
$orExpr
);
$qb
->
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))'
);
}
...
...
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