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
c950aab1
Unverified
Commit
c950aab1
authored
Jan 18, 2020
by
Sergei Morozov
Committed by
GitHub
Jan 18, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3830 from BenMorel/sql-part-join
Introduce Join class in QueryBuilder
parents
6e4599d5
58c104a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
28 deletions
+60
-28
Join.php
lib/Doctrine/DBAL/Query/Join.php
+46
-0
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+14
-28
No files found.
lib/Doctrine/DBAL/Query/Join.php
0 → 100644
View file @
c950aab1
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Query
;
/**
* @internal
*/
final
class
Join
{
/** @var string */
public
$type
;
/** @var string */
public
$table
;
/** @var string */
public
$alias
;
/** @var string|null */
public
$condition
;
private
function
__construct
(
string
$type
,
string
$table
,
string
$alias
,
?
string
$condition
)
{
$this
->
type
=
$type
;
$this
->
table
=
$table
;
$this
->
alias
=
$alias
;
$this
->
condition
=
$condition
;
}
public
static
function
inner
(
string
$table
,
string
$alias
,
?
string
$condition
)
:
Join
{
return
new
self
(
'INNER'
,
$table
,
$alias
,
$condition
);
}
public
static
function
left
(
string
$table
,
string
$alias
,
?
string
$condition
)
:
Join
{
return
new
self
(
'LEFT'
,
$table
,
$alias
,
$condition
);
}
public
static
function
right
(
string
$table
,
string
$alias
,
?
string
$condition
)
:
Join
{
return
new
self
(
'RIGHT'
,
$table
,
$alias
,
$condition
);
}
}
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
c950aab1
...
...
@@ -20,7 +20,6 @@ use function implode;
use
function
is_array
;
use
function
is_object
;
use
function
key
;
use
function
strtoupper
;
use
function
substr
;
/**
...
...
@@ -426,7 +425,7 @@ class QueryBuilder
foreach
(
$sqlPart
as
$part
)
{
$this
->
sqlParts
[
$sqlPartName
][]
=
$part
;
}
}
elseif
(
$isArray
&&
is_array
(
$sqlPart
[
key
(
$sqlPart
)]
))
{
}
elseif
(
$isArray
&&
(
is_array
(
$sqlPart
[
key
(
$sqlPart
)])
||
is_object
(
$sqlPart
[
key
(
$sqlPart
)])
))
{
$key
=
key
(
$sqlPart
);
$this
->
sqlParts
[
$sqlPartName
][
$key
][]
=
$sqlPart
[
$key
];
}
elseif
(
$isMultiple
)
{
...
...
@@ -673,12 +672,7 @@ class QueryBuilder
public
function
innerJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
'joinType'
=>
'inner'
,
'joinTable'
=>
$join
,
'joinAlias'
=>
$alias
,
'joinCondition'
=>
$condition
,
],
$fromAlias
=>
Join
::
inner
(
$join
,
$alias
,
$condition
),
],
true
);
}
...
...
@@ -702,12 +696,7 @@ class QueryBuilder
public
function
leftJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
'joinType'
=>
'left'
,
'joinTable'
=>
$join
,
'joinAlias'
=>
$alias
,
'joinCondition'
=>
$condition
,
],
$fromAlias
=>
Join
::
left
(
$join
,
$alias
,
$condition
),
],
true
);
}
...
...
@@ -731,12 +720,7 @@ class QueryBuilder
public
function
rightJoin
(
string
$fromAlias
,
string
$join
,
string
$alias
,
?
string
$condition
=
null
)
{
return
$this
->
add
(
'join'
,
[
$fromAlias
=>
[
'joinType'
=>
'right'
,
'joinTable'
=>
$join
,
'joinAlias'
=>
$alias
,
'joinCondition'
=>
$condition
,
],
$fromAlias
=>
Join
::
right
(
$join
,
$alias
,
$condition
),
],
true
);
}
...
...
@@ -770,7 +754,7 @@ class QueryBuilder
* ->from('counters', 'c')
* ->where('c.id = ?');
*
* // You can optionally programatically build and/or expressions
* // You can optionally program
m
atically build and/or expressions
* $qb = $conn->createQueryBuilder();
*
* $or = $qb->expr()->orx();
...
...
@@ -1315,17 +1299,19 @@ class QueryBuilder
if
(
isset
(
$this
->
sqlParts
[
'join'
][
$fromAlias
]))
{
foreach
(
$this
->
sqlParts
[
'join'
][
$fromAlias
]
as
$join
)
{
if
(
array_key_exists
(
$join
[
'joinAlias'
],
$knownAliases
))
{
throw
NonUniqueAlias
::
new
(
$join
[
'joinAlias'
],
array_keys
(
$knownAliases
));
/** @var Join $join */
if
(
array_key_exists
(
$join
->
alias
,
$knownAliases
))
{
throw
NonUniqueAlias
::
new
(
$join
->
alias
,
array_keys
(
$knownAliases
));
}
$sql
.=
' '
.
strtoupper
(
$join
[
'joinType'
])
.
' JOIN '
.
$join
[
'joinTable'
]
.
' '
.
$join
[
'joinAlias'
]
.
' ON '
.
((
string
)
$join
[
'joinCondition'
]
);
$knownAliases
[
$join
[
'joinAlias'
]
]
=
true
;
$sql
.=
' '
.
$join
->
type
.
' JOIN '
.
$join
->
table
.
' '
.
$join
->
alias
.
' ON '
.
((
string
)
$join
->
condition
);
$knownAliases
[
$join
->
alias
]
=
true
;
}
foreach
(
$this
->
sqlParts
[
'join'
][
$fromAlias
]
as
$join
)
{
$sql
.=
$this
->
getSQLForJoins
(
$join
[
'joinAlias'
],
$knownAliases
);
/** @var Join $join */
$sql
.=
$this
->
getSQLForJoins
(
$join
->
alias
,
$knownAliases
);
}
}
...
...
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