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
a2e87c57
Commit
a2e87c57
authored
Nov 08, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hotfix/#722-connection-delete-with-empty-criteria'
Close #722
parents
b86688ba
49e9e9ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
Connection.php
lib/Doctrine/DBAL/Connection.php
+19
-7
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+16
-0
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
a2e87c57
...
...
@@ -575,19 +575,31 @@ class Connection implements DriverConnection
{
$this
->
connect
();
return
$this
->
executeUpdate
(
'DELETE FROM '
.
$tableExpression
.
$this
->
getWhereSql
(
$identifier
),
array_values
(
$identifier
),
is_string
(
key
(
$types
))
?
$this
->
extractTypeValues
(
$identifier
,
$types
)
:
$types
);
}
/**
* @param array $identifier An associative array containing column-value pairs.
*
* @return string
*/
private
function
getWhereSql
(
array
$identifier
)
{
if
(
empty
(
$identifier
))
{
return
''
;
}
$criteria
=
array
();
foreach
(
array_keys
(
$identifier
)
as
$columnName
)
{
$criteria
[]
=
$columnName
.
' = ?'
;
}
if
(
is_string
(
key
(
$types
)))
{
$types
=
$this
->
extractTypeValues
(
$identifier
,
$types
);
}
$query
=
'DELETE FROM '
.
$tableExpression
.
' WHERE '
.
implode
(
' AND '
,
$criteria
);
return
$this
->
executeUpdate
(
$query
,
array_values
(
$identifier
),
$types
);
return
' WHERE '
.
implode
(
' AND '
,
$criteria
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
a2e87c57
...
...
@@ -466,4 +466,20 @@ SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\"");
$this
->
assertTrue
(
$conn
->
isConnected
(),
"Connection is not connected after passing external PDO"
);
}
public
function
testCallingDeleteWithNoDeletionCriteriaResultsInSqlWithoutWhereClause
()
{
$pdoMock
=
$this
->
getMock
(
'Doctrine\DBAL\Driver\Connection'
);
$pdoMock
->
expects
(
$this
->
once
())
->
method
(
'exec'
)
->
with
(
$this
->
equalTo
(
'DELETE FROM kittens'
));
$conn
=
new
Connection
(
array
(
'pdo'
=>
$pdoMock
),
$this
->
getMock
(
'Doctrine\DBAL\Driver'
)
);
$conn
->
delete
(
'kittens'
,
array
());
}
}
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