1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Doctrine_Db now supports pending attributes => lazy connecting now possible

This commit is contained in:
zYne 2007-01-04 20:37:35 +00:00
parent f900a51a7d
commit b636861742

View File

@ -69,6 +69,12 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'username' => null,
'password' => null,
);
/**
* @var array $pendingAttributes An array of pending attributes. When setting attributes
* no connection is needed. When connected all the pending
* attributes are passed to the underlying PDO instance.
*/
protected $pendingAttributes = array();
/**
* @var Doctrine_Db_EventListener_Interface|Doctrine_Overloadable $listener
* listener for listening events
@ -186,6 +192,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->dbh->setAttribute(PDO::ATTR_STATEMENT_CLASS, array("Doctrine_Db_Statement", array($this)));
foreach($this->pendingAttributes as $attr => $value) {
$this->dbh->setAttribute($attr, $value);
}
$this->isConnected = true;
return true;
}
@ -275,6 +286,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
default:
throw new Doctrine_Db_Exception('Unknown driver '.$parts['scheme']);
}
$this->pendingAttributes[PDO::ATTR_DRIVER_NAME] = $parts['scheme'];
return $parts;
}
@ -463,9 +475,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/
public function getAttribute($attribute)
{
$this->connect();
if ($this->isConnected) {
return $this->dbh->getAttribute($attribute);
} else {
if ( ! isset($this->pendingAttributes[$attribute])) {
throw new Doctrine_Db_Exception('Attribute ' . $attribute . ' not found.');
}
return $this->pendingAttributes[$attribute];
}
}
/**
* returns an array of available PDO drivers
@ -484,9 +502,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
*/
public function setAttribute($attribute, $value)
{
$this->connect();
if ($this->isConnected) {
$this->dbh->setAttribute($attribute, $value);
} else {
$this->pendingAttributes[$attribute] = $value;
}
}
/**
* getIterator