From 8f114275959dac6e771d68b03e5935c06cc8e82a Mon Sep 17 00:00:00 2001 From: zYne Date: Sat, 10 Nov 2007 10:37:10 +0000 Subject: [PATCH] added Doctrine_Connection::delete() method (needed as a convenience method as well as for the upcoming CTI support) --- lib/Doctrine/Connection.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index d0565ef03..6e5d02bb7 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -501,6 +501,30 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun return $affectedRows; } + /** + * deletes table row(s) matching the specified identifier + * + * @throws Doctrine_Connection_Exception if something went wrong at the database level + * @param string $table The table to delete data from + * @param array $identifier An associateve array containing identifier column-value pairs. + * @return integer The number of affected rows + */ + public function delete($table, array $identifier) + { + $tmp = array(); + + foreach (array_keys($identifier) as $id) { + $tmp[] = $id . ' = ? '; + } + + $query = 'DELETE FROM ' + . $this->conn->quoteIdentifier($table) + . ' WHERE ' . implode(' AND ', $tmp); + + + return $this->conn->exec($query, array_values($identifier)); + } + /** * Updates table row(s) with specified data * @@ -541,7 +565,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * * @param string $table The table to insert data into. * @param array $values An associateve array containing column-value pairs. - * @return boolean + * @return mixed boolean false if empty value array was given, + * otherwise returns the number of affected rows */ public function insert($table, array $values) { if (empty($values)) { @@ -570,9 +595,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $query .= implode(', ', $a) . ')'; // prepare and execute the statement - $this->exec($query, array_values($values)); - - return true; + return $this->exec($query, array_values($values)); } /**