Commit 01c93d3e authored by runa's avatar runa

bulkdelete delete multikey rows

parent f402f879
......@@ -127,21 +127,35 @@ class Doctrine_Transaction extends Doctrine_Connection_Module
foreach ($this->delete as $name => $deletes) {
$record = false;
$ids = array();
foreach ($deletes as $k => $record) {
$ids[] = $record->getIncremented();
$record->assignIdentifier(false);
}
if ($record instanceof Doctrine_Record) {
$params = substr(str_repeat("?, ",count($ids)),0,-2);
$query = 'DELETE FROM '
. $record->getTable()->getTableName()
. ' WHERE '
. $record->getTable()->getIdentifier()
. ' IN(' . $params . ')';
if (is_array($deletes[count($deletes)-1]->getTable()->getIdentifier())){
foreach($deletes as $k => $record){
$cond = '';
$ids = $record->obtainIdentifier();
$query = 'DELETE FROM '.$record->getTable()->getTableName().' WHERE ';
foreach(array_keys($ids) as $id){
if ($cond){ $cond .= " AND ";}
$cond .= " $id = ? ";
}
$query = $query . $cond;
$this->conn->execute($query, array_values($ids));
}
}else{
foreach ($deletes as $k => $record) {
$ids[] = $record->getIncremented();
$record->assignIdentifier(false);
}
if ($record instanceof Doctrine_Record) {
$params = substr(str_repeat("?, ",count($ids)),0,-2);
$query = 'DELETE FROM '
. $record->getTable()->getTableName()
. ' WHERE '
. $record->getTable()->getIdentifier()
. ' IN(' . $params . ')';
$this->conn->execute($query, $ids);
}
$this->conn->execute($query, $ids);
}
}
}
$this->delete = array();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment