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
ce32c090
Unverified
Commit
ce32c090
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
77a76d86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
QueryBuilder.php
lib/Doctrine/DBAL/Query/QueryBuilder.php
+17
-3
QueryBuilderTest.php
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
+29
-0
No files found.
lib/Doctrine/DBAL/Query/QueryBuilder.php
View file @
ce32c090
...
@@ -1128,7 +1128,7 @@ class QueryBuilder
...
@@ -1128,7 +1128,7 @@ class QueryBuilder
// Loop through all FROM clauses
// Loop through all FROM clauses
foreach
(
$this
->
sqlParts
[
'from'
]
as
$from
)
{
foreach
(
$this
->
sqlParts
[
'from'
]
as
$from
)
{
if
(
$from
[
'alias'
]
===
null
)
{
if
(
$from
[
'alias'
]
===
null
||
$from
[
'alias'
]
===
$from
[
'table'
]
)
{
$tableSql
=
$from
[
'table'
];
$tableSql
=
$from
[
'table'
];
$tableReference
=
$from
[
'table'
];
$tableReference
=
$from
[
'table'
];
}
else
{
}
else
{
...
@@ -1187,7 +1187,14 @@ class QueryBuilder
...
@@ -1187,7 +1187,14 @@ class QueryBuilder
*/
*/
private
function
getSQLForUpdate
()
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
return
'UPDATE '
.
$table
.
' SET '
.
implode
(
', '
,
$this
->
sqlParts
[
'set'
])
.
' SET '
.
implode
(
', '
,
$this
->
sqlParts
[
'set'
])
.
(
$this
->
sqlParts
[
'where'
]
!==
null
?
' WHERE '
.
((
string
)
$this
->
sqlParts
[
'where'
])
:
''
);
.
(
$this
->
sqlParts
[
'where'
]
!==
null
?
' WHERE '
.
((
string
)
$this
->
sqlParts
[
'where'
])
:
''
);
...
@@ -1200,7 +1207,14 @@ class QueryBuilder
...
@@ -1200,7 +1207,14 @@ class QueryBuilder
*/
*/
private
function
getSQLForDelete
()
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'
])
:
''
);
return
'DELETE FROM '
.
$table
.
(
$this
->
sqlParts
[
'where'
]
!==
null
?
' WHERE '
.
((
string
)
$this
->
sqlParts
[
'where'
])
:
''
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
View file @
ce32c090
...
@@ -411,6 +411,16 @@ class QueryBuilderTest extends DbalTestCase
...
@@ -411,6 +411,16 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'UPDATE users SET foo = ?, bar = ?'
,
(
string
)
$qb
);
self
::
assertEquals
(
'UPDATE users SET foo = ?, bar = ?'
,
(
string
)
$qb
);
}
}
public
function
testUpdateWithMatchingAlias
()
{
$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
()
public
function
testUpdateWhere
()
{
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
=
new
QueryBuilder
(
$this
->
conn
);
...
@@ -448,6 +458,15 @@ class QueryBuilderTest extends DbalTestCase
...
@@ -448,6 +458,15 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'DELETE FROM users'
,
(
string
)
$qb
);
self
::
assertEquals
(
'DELETE FROM users'
,
(
string
)
$qb
);
}
}
public
function
testDeleteWithMatchingAlias
()
{
$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
()
public
function
testDeleteWhere
()
{
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
=
new
QueryBuilder
(
$this
->
conn
);
...
@@ -776,6 +795,16 @@ class QueryBuilderTest extends DbalTestCase
...
@@ -776,6 +795,16 @@ class QueryBuilderTest extends DbalTestCase
self
::
assertEquals
(
'SELECT id FROM users'
,
(
string
)
$qb
);
self
::
assertEquals
(
'SELECT id FROM users'
,
(
string
)
$qb
);
}
}
public
function
testSimpleSelectWithMatchingTableAlias
()
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$qb
->
select
(
'id'
)
->
from
(
'users'
,
'users'
);
self
::
assertEquals
(
'SELECT id FROM users'
,
(
string
)
$qb
);
}
public
function
testSelectWithSimpleWhereWithoutTableAlias
()
public
function
testSelectWithSimpleWhereWithoutTableAlias
()
{
{
$qb
=
new
QueryBuilder
(
$this
->
conn
);
$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