diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 3ea6b6da5..bb9d6c35c 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -150,6 +150,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ public function driverName($name) { } + /** + * supports + * + * @param string $feature the name of the feature + * @return boolean whether or not this drivers supports given feature + */ + public function supports($feature) { + return (isset($this->supported[$feature]) && + $this->supported[$feature] === 'emulated' || + $this->supported[$feature]); + } /** * returns a datadict object * @@ -316,6 +327,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun /** * query * queries the database using Doctrine Query Language + * returns a collection of Doctrine_Record objects * * * $users = $conn->query('SELECT u.* FROM User u'); @@ -333,6 +345,34 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun return $parser->query($query, $params); } + /** + * query + * queries the database using Doctrine Query Language and returns + * the first record found + * + * + * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.id = ?', array(1)); + * + * $user = $conn->queryOne('SELECT u.* FROM User u WHERE u.name LIKE ? AND u.password = ?', + * array('someone', 'password') + * ); + * + * + * @param string $query DQL query + * @param array $params query parameters + * @see Doctrine_Query + * @return Doctrine_Record|false Doctrine_Record object on success, + * boolean false on failure + */ + public function queryOne($query, array $params = array()) { + $parser = new Doctrine_Query($this); + + $coll = $parser->query($query, $params); + if( ! $coll->contains(0)) + return false; + + return $coll[0]; + } /** * queries the database with limit and offset * added to the query and returns a PDOStatement object @@ -583,7 +623,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $record->getTable()->getListener()->onDelete($record); $this->commit(); - + return true; } /**