* @param string $savepoint name of a savepoint to release
* @throws Doctrine_Transaction_Exception if the transaction fails at PDO level
* @throws Doctrine_Validator_Exception if the transaction fails due to record validations
* @return boolean false if commit couldn't be performed, true otherwise
*/
publicfunctioncount()
publicfunctioncommit($savepoint=null)
{
return$this->_count;
return$this->transaction->commit($savepoint);
}
/**
* create
* creates a record
* rollback
* Cancel any database changes done during a transaction or since a specific
* savepoint that is in progress. This function may only be called when
* auto-committing is disabled, otherwise it will fail. Therefore, a new
* transaction is implicitly started after canceling the pending changes.
*
* create creates a record
* @param string $name component name
* @return Doctrine_Record Doctrine_Record object
* @todo Any strong reasons why this should not be removed?
* @todo package:orm
* this method can be listened with onPreTransactionRollback and onTransactionRollback
* eventlistener methods
*
* @param string $savepoint name of a savepoint to rollback to
* @throws Doctrine_Transaction_Exception if the rollback operation fails at database level
* @return boolean false if rollback couldn't be performed, true otherwise
*/
publicfunctioncreate($name)
publicfunctionrollback($savepoint=null)
{
return$this->getMapper($name)->create();
$this->transaction->rollback($savepoint);
}
/**
* Creates a new Doctrine_Query object that operates on this connection.
* createDatabase
*
* @return Doctrine_Query
* @todo package:orm
* Method for creating the database for the connection instance
*
* @return mixed Will return an instance of the exception thrown if the create database fails, otherwise it returns a string detailing the success
*/
publicfunctioncreateQuery($dql="")
publicfunctioncreateDatabase()
{
$query=newDoctrine_Query($this);
if(!empty($dql)){
$query->parseQuery($dql);
try{
if(!$dsn=$this->getOption('dsn')){
thrownewDoctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
}
return$query;
$manager=$this->getManager();
$info=$manager->parsePdoDsn($dsn);
$username=$this->getOption('username');
$password=$this->getOption('password');
// Make connection without database specified so we can create it
return'Successfully created database for connection "'.$this->getName().'" named "'.$info['dbname'].'"';
}catch(Exception$e){
return$e;
}
}
/**
* flush
* saves all the records from all tables
* this operation is isolated using a transaction
* dropDatabase
*
* @throws PDOException if something went wrong at database level
* @return void
* @todo package:orm
* Method for dropping the database for the connection instance
*
* @return mixed Will return an instance of the exception thrown if the drop database fails, otherwise it returns a string detailing the success
*/
publicfunctionflush()
publicfunctiondropDatabase()
{
$this->beginInternalTransaction();
$this->unitOfWork->flush();
$this->commit();
}
try{
if(!$dsn=$this->getOption('dsn')){
thrownewDoctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
}
$info=$this->getManager()->parsePdoDsn($dsn);
$this->export->dropDatabase($info['dbname']);
return'Successfully dropped database for connection "'.$this->getName().'" named "'.$info['dbname'].'"';
* ----------- Mixed methods (need to figure out where they go) ---------------
*/
/**
* createDatabase
*
* Method for creating the database for the connection instance
* getAttribute
* retrieves a database connection attribute
*
* @return mixed Will return an instance of the exception thrown if the create database fails, otherwise it returns a string detailing the success
* @param integer $attribute
* @return mixed
*/
publicfunctioncreateDatabase()
publicfunctiongetAttribute($attribute)
{
try{
if(!$dsn=$this->getOption('dsn')){
thrownewDoctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
if($attribute>=100){
if(!isset($this->_attributes[$attribute])){
returnparent::getAttribute($attribute);
}
return$this->_attributes[$attribute];
}
$manager=$this->getManager();
$info=$manager->parsePdoDsn($dsn);
$username=$this->getOption('username');
$password=$this->getOption('password');
// Make connection without database specified so we can create it
return'Successfully created database for connection "'.$this->getName().'" named "'.$info['dbname'].'"';
if($this->isConnected){
try{
return$this->dbh->getAttribute($attribute);
}catch(Exception$e){
return$e;
thrownewDoctrine_Connection_Exception('Attribute '.$attribute.' not found.');
}
}else{
if(!isset($this->pendingAttributes[$attribute])){
$this->connect();
$this->getAttribute($attribute);
}
return$this->pendingAttributes[$attribute];
}
}
/**
* dropDatabase
* setAttribute
* sets an attribute
*
* Method for dropping the database for the connection instance
* @todo why check for >= 100? has this any special meaning when creating
* attributes?
*
* @return mixed Will return an instance of the exception thrown if the drop database fails, otherwise it returns a string detailing the success
* @param integer $attribute
* @param mixed $value
* @return boolean
*/
publicfunctiondropDatabase()
publicfunctionsetAttribute($attribute,$value)
{
try{
if(!$dsn=$this->getOption('dsn')){
thrownewDoctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality');
if($attribute>=100){
parent::setAttribute($attribute,$value);
}else{
if($this->isConnected){
$this->dbh->setAttribute($attribute,$value);
}else{
$this->pendingAttributes[$attribute]=$value;
}
$info=$this->getManager()->parsePdoDsn($dsn);
$this->export->dropDatabase($info['dbname']);
return'Successfully dropped database for connection "'.$this->getName().'" named "'.$info['dbname'].'"';
}catch(Exception$e){
return$e;
}
return$this;
}
/**
* returns a string representation of this object
* @return string
* __get
* lazy loads given module and returns it
*
* @see Doctrine_DataDict
* @see Doctrine_Expression
* @see Doctrine_Export
* @see Doctrine_Transaction
* @see Doctrine_Connection::$modules all availible modules
* @param string $name the name of the module to get
* @throws Doctrine_Connection_Exception if trying to get an unknown module