Show
Ignore:
Timestamp:
02/15/08 11:50:08 (2 years ago)
Author:
jwage
Message:

Merging r3565 to 0.9 branch.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/lib/Doctrine/Connection.php

    r3131 r3787  
    6868 
    6969    /** 
    70      * @var string $driverName                  the name of this connection driver 
     70     * $_name 
     71     * 
     72     * Name of the connection 
     73     * 
     74     * @var string $_name 
     75     */ 
     76    protected $_name; 
     77 
     78    /** 
     79     * The name of this connection driver. 
     80     * 
     81     * @var string $driverName                   
    7182     */ 
    7283    protected $driverName; 
     
    289300    public function getName() 
    290301    { 
     302        return $this->_name; 
     303    } 
     304 
     305    /** 
     306     * setName 
     307     * 
     308     * Sets the name of the connection 
     309     * 
     310     * @param string $name  
     311     * @return void 
     312     */ 
     313    public function setName($name) 
     314    { 
     315        $this->_name = $name; 
     316    } 
     317 
     318    /** 
     319     * getDriverName 
     320     * 
     321     * Gets the name of the instance driver 
     322     * 
     323     * @return void 
     324     */ 
     325    public function getDriverName() 
     326    { 
    291327        return $this->driverName; 
    292328    } 
     
    323359                    break; 
    324360                default: 
    325                     $class = 'Doctrine_' . ucwords($name) . '_' . $this->getName(); 
     361                    $class = 'Doctrine_' . ucwords($name) . '_' . $this->getDriverName(); 
    326362                    $this->modules[$name] = new $class($this); 
    327363                } 
     
    12621298    } 
    12631299 
     1300    public function createDatabase() 
     1301    { 
     1302        try { 
     1303            if ( ! $dsn = $this->getOption('dsn')) { 
     1304                throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     1305            } 
     1306 
     1307            $manager = $this->getManager(); 
     1308 
     1309            $info = $manager->parsePdoDsn($dsn); 
     1310            $username = $this->getOption('username'); 
     1311            $password = $this->getOption('password'); 
     1312 
     1313            // Make connection without database specified so we can create it 
     1314            $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
     1315 
     1316            // Create database 
     1317            $connect->export->createDatabase($info['dbname']); 
     1318 
     1319            // Close the tmp connection with no database 
     1320            $manager->closeConnection($connect); 
     1321 
     1322            // Close original connection 
     1323            $manager->closeConnection($this); 
     1324 
     1325            // Reopen original connection with newly created database 
     1326            $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); 
     1327 
     1328            return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1329        } catch (Exception $e) { 
     1330            return $e; 
     1331        } 
     1332    } 
     1333 
     1334    /** 
     1335     * dropDatabase 
     1336     * 
     1337     * Method for dropping the database for the connection instance 
     1338     * 
     1339     * @return mixed Will return an instance of the exception thrown if the drop database fails, otherwise it returns a string detailing the success 
     1340     */ 
     1341    public function dropDatabase() 
     1342    { 
     1343      try { 
     1344          if ( ! $dsn = $this->getOption('dsn')) { 
     1345              throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     1346          } 
     1347 
     1348          $info = $this->getManager()->parsePdoDsn($dsn); 
     1349 
     1350          $this->export->dropDatabase($info['dbname']); 
     1351 
     1352          return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1353      } catch (Exception $e) { 
     1354          return $e; 
     1355      } 
     1356    } 
     1357 
    12641358    /** 
    12651359     * returns a string representation of this object