1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Added Doctrine_Connection::queryOne()

This commit is contained in:
zYne 2006-11-01 15:07:04 +00:00
parent ad595dd839
commit 6b4e032857

View File

@ -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
*
* <code>
* $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
*
* <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
* 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;
}
/**