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
84328cd9
Commit
84328cd9
authored
Jan 27, 2020
by
Benjamin Morel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace andX/orX with and/or
parent
c2b8e6e8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
25 deletions
+39
-25
UPGRADE.md
UPGRADE.md
+6
-0
query-builder.rst
docs/en/reference/query-builder.rst
+2
-2
ExpressionBuilder.php
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
+22
-14
ExpressionBuilderTest.php
...ine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
+8
-8
QueryBuilderTest.php
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+1
-1
No files found.
UPGRADE.md
View file @
84328cd9
# Upgrade to 2.11
## Deprecated `ExpressionBuilder` methods
The usage of the
`andX()`
and
`orX()`
methods of the
`ExpressionBuilder`
class has been deprecated. Use
`and()`
and
`or()`
instead.
# Upgrade to 2.10
## Deprecated `Doctrine\DBAL\Event\ConnectionEventArgs` methods
...
...
docs/en/reference/query-builder.rst
View file @
84328cd9
...
...
@@ -332,13 +332,13 @@ Most notably you can use expressions to build nested And-/Or statements:
->select('id', 'name')
->from('users')
->where(
$queryBuilder->expr()->and
X
(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('username', '?'),
$queryBuilder->expr()->eq('email', '?')
)
);
The ``and
X()`` and ``orX
()`` methods accept an arbitrary amount
The ``and
()`` and ``or
()`` methods accept an arbitrary amount
of arguments and can be nested in each other.
There is a bunch of methods to create comparisons and other SQL snippets
...
...
lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
View file @
84328cd9
...
...
@@ -39,13 +39,27 @@ class ExpressionBuilder
}
/**
* Creates a conjunction of the given
boolean
expressions.
* Creates a conjunction of the given expressions.
*
* Example:
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
public
function
and
(
...
$expressions
)
:
CompositeExpression
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
$expressions
);
}
/**
* Creates a disjunction of the given expressions.
*
* [php]
* // (u.type = ?) AND (u.role = ?)
* $expr->andX('u.type = ?', 'u.role = ?'));
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
public
function
or
(
...
$expressions
)
:
CompositeExpression
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
$expressions
);
}
/**
* @deprecated Use `and()` instead.
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
...
...
@@ -54,17 +68,11 @@ class ExpressionBuilder
*/
public
function
andX
(
$x
=
null
)
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_AND
,
func_get_args
());
return
$this
->
and
(
...
func_get_args
());
}
/**
* Creates a disjunction of the given boolean expressions.
*
* Example:
*
* [php]
* // (u.type = ?) OR (u.role = ?)
* $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
* @deprecated Use `or()` instead.
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
...
...
@@ -73,7 +81,7 @@ class ExpressionBuilder
*/
public
function
orX
(
$x
=
null
)
{
return
new
CompositeExpression
(
CompositeExpression
::
TYPE_OR
,
func_get_args
());
return
$this
->
or
(
...
func_get_args
());
}
/**
...
...
tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php
View file @
84328cd9
...
...
@@ -29,11 +29,11 @@ class ExpressionBuilderTest extends DbalTestCase
/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForAnd
X
* @dataProvider provideDataForAnd
*/
public
function
testAnd
X
(
array
$parts
,
string
$expected
)
:
void
public
function
testAnd
(
array
$parts
,
string
$expected
)
:
void
{
$composite
=
$this
->
expr
->
and
X
();
$composite
=
$this
->
expr
->
and
();
foreach
(
$parts
as
$part
)
{
$composite
->
add
(
$part
);
...
...
@@ -45,7 +45,7 @@ class ExpressionBuilderTest extends DbalTestCase
/**
* @return mixed[][]
*/
public
static
function
provideDataForAnd
X
()
:
iterable
public
static
function
provideDataForAnd
()
:
iterable
{
return
[
[
...
...
@@ -90,11 +90,11 @@ class ExpressionBuilderTest extends DbalTestCase
/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForOr
X
* @dataProvider provideDataForOr
*/
public
function
testOr
X
(
array
$parts
,
string
$expected
)
:
void
public
function
testOr
(
array
$parts
,
string
$expected
)
:
void
{
$composite
=
$this
->
expr
->
or
X
();
$composite
=
$this
->
expr
->
or
();
foreach
(
$parts
as
$part
)
{
$composite
->
add
(
$part
);
...
...
@@ -106,7 +106,7 @@ class ExpressionBuilderTest extends DbalTestCase
/**
* @return mixed[][]
*/
public
static
function
provideDataForOr
X
()
:
iterable
public
static
function
provideDataForOr
()
:
iterable
{
return
[
[
...
...
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
View file @
84328cd9
...
...
@@ -68,7 +68,7 @@ class QueryBuilderTest extends DbalTestCase
$qb
->
select
(
'u.id'
)
->
from
(
'users'
,
'u'
)
->
where
(
$expr
->
and
X
(
$expr
->
eq
(
'u.nickname'
,
'?'
)));
->
where
(
$expr
->
and
(
$expr
->
eq
(
'u.nickname'
,
'?'
)));
self
::
assertEquals
(
'SELECT u.id FROM users u WHERE u.nickname = ?'
,
(
string
)
$qb
);
}
...
...
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