Commit 6b4e0328 authored by zYne's avatar zYne

Added Doctrine_Connection::queryOne()

parent ad595dd8
...@@ -150,6 +150,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -150,6 +150,17 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*/ */
public function driverName($name) { 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 * returns a datadict object
* *
...@@ -316,6 +327,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -316,6 +327,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* query * query
* queries the database using Doctrine Query Language * queries the database using Doctrine Query Language
* returns a collection of Doctrine_Record objects
* *
* <code> * <code>
* $users = $conn->query('SELECT u.* FROM User u'); * $users = $conn->query('SELECT u.* FROM User u');
...@@ -333,6 +345,34 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -333,6 +345,34 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $parser->query($query, $params); return $parser->query($query, $params);
} }
/**
* query
* queries the database using Doctrine Query Language and returns
* the first record found
*
* <code>
* $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')
* );
* </code>
*
* @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 * queries the database with limit and offset
* added to the query and returns a PDOStatement object * added to the query and returns a PDOStatement object
...@@ -583,7 +623,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -583,7 +623,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$record->getTable()->getListener()->onDelete($record); $record->getTable()->getListener()->onDelete($record);
$this->commit(); $this->commit();
return true; return true;
} }
/** /**
......
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