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
0a18df20
Unverified
Commit
0a18df20
authored
Mar 13, 2018
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When rendering SQL, only render the alias if it's different from the table name
parent
ee5e4a75
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
3 deletions
+44
-3
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+15
-3
QueryBuilderTest.php
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+29
-0
No files found.
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
0a18df20
...
...
@@ -1152,7 +1152,7 @@ class QueryBuilder
// Loop through all FROM clauses
foreach
(
$this
->
sqlParts
[
'from'
]
as
$from
)
{
if
(
$from
[
'alias'
]
===
null
)
{
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
]
)
{
$tableSql
=
$from
[
'table'
];
$tableReference
=
$from
[
'table'
];
}
else
{
...
...
@@ -1211,7 +1211,13 @@ class QueryBuilder
*/
private
function
getSQLForUpdate
()
{
$table
=
$this
->
sqlParts
[
'from'
][
'table'
]
.
(
$this
->
sqlParts
[
'from'
][
'alias'
]
?
' '
.
$this
->
sqlParts
[
'from'
][
'alias'
]
:
''
);
$from
=
$this
->
sqlParts
[
'from'
];
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
])
{
$table
=
$from
[
'table'
];
}
else
{
$table
=
$from
[
'table'
]
.
' '
.
$from
[
'alias'
];
}
return
'UPDATE '
.
$table
.
' SET '
.
implode
(
', '
,
$this
->
sqlParts
[
'set'
])
...
...
@@ -1225,7 +1231,13 @@ class QueryBuilder
*/
private
function
getSQLForDelete
()
{
$table
=
$this
->
sqlParts
[
'from'
][
'table'
]
.
(
$this
->
sqlParts
[
'from'
][
'alias'
]
?
' '
.
$this
->
sqlParts
[
'from'
][
'alias'
]
:
''
);
$from
=
$this
->
sqlParts
[
'from'
];
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
])
{
$table
=
$from
[
'table'
];
}
else
{
$table
=
$from
[
'table'
]
.
' '
.
$from
[
'alias'
];
}
return
'DELETE FROM '
.
$table
.
(
$this
->
sqlParts
[
'where'
]
!==
null
?
' WHERE '
.
((
string
)
$this
->
sqlParts
[
'where'
])
:
''
);
}
...
...
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
View file @
0a18df20
...
...
@@ -422,6 +422,16 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'UPDATE users SET foo = ?, bar = ?'
,
(
string
)
$qb
);
}
public
function
testUpdateWithMatchingAlias
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
update
(
'users'
,
'users'
)
->
set
(
'foo'
,
'?'
)
->
set
(
'bar'
,
'?'
);
self
::
assertEquals
(
'UPDATE users SET foo = ?, bar = ?'
,
(
string
)
$qb
);
}
public
function
testUpdateWhere
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
...
...
@@ -459,6 +469,15 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'DELETE FROM users'
,
(
string
)
$qb
);
}
public
function
testDeleteWithMatchingAlias
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
delete
(
'users'
,
'users'
);
self
::
assertEquals
(
QueryBuilder
::
DELETE
,
$qb
->
getType
());
self
::
assertEquals
(
'DELETE FROM users'
,
(
string
)
$qb
);
}
public
function
testDeleteWhere
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
...
...
@@ -787,6 +806,16 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'SELECT id FROM users'
,
(
string
)
$qb
);
}
public
function
testSimpleSelectWithMatchingTableAlias
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
select
(
'id'
)
->
from
(
'users'
,
'users'
);
self
::
assertEquals
(
'SELECT id FROM users'
,
(
string
)
$qb
);
}
public
function
testSelectWithSimpleWhereWithoutTableAlias
()
:
void
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
...
...
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