Changeset 3566

Show
Ignore:
Timestamp:
01/22/08 16:58:03 (3 years ago)
Author:
jwage
Message:

-

Location:
trunk/lib/Doctrine
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/Connection.php

    r3565 r3566  
    14031403     * createDatabase 
    14041404     * 
    1405      * @return void 
     1405     * Method for creating the database for the connection instance 
     1406     * 
     1407     * @return mixed Will return an instance of the exception thrown if the create database fails, otherwise it returns a string detailing the success 
    14061408     */ 
    14071409    public function createDatabase() 
    14081410    { 
    1409       $manager = $this->getManager(); 
    1410  
    1411       $info = $manager->parsePdoDsn($this->getOption('dsn')); 
    1412       $username = $this->getOption('username'); 
    1413       $password = $this->getOption('password'); 
    1414  
    1415       // Make connection without database specified so we can create it 
    1416       $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
    1417        
     1411        try { 
     1412            if ( ! $dsn = $this->getOption('dsn')) { 
     1413                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'); 
     1414            } 
     1415 
     1416            $manager = $this->getManager(); 
     1417 
     1418            $info = $manager->parsePdoDsn($dsn); 
     1419            $username = $this->getOption('username'); 
     1420            $password = $this->getOption('password'); 
     1421 
     1422            // Make connection without database specified so we can create it 
     1423            $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
     1424 
     1425            // Create database 
     1426            $connect->export->createDatabase($info['dbname']); 
     1427 
     1428            // Close the tmp connection with no database 
     1429            $manager->closeConnection($connect); 
     1430 
     1431            // Close original connection 
     1432            $manager->closeConnection($this); 
     1433 
     1434            // Reopen original connection with newly created database 
     1435            $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); 
     1436 
     1437            return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1438        } catch (Exception $e) { 
     1439            return $e; 
     1440        } 
     1441    } 
     1442 
     1443    /** 
     1444     * dropDatabase 
     1445     * 
     1446     * Method for dropping the database for the connection instance 
     1447     * 
     1448     * @return mixed Will return an instance of the exception thrown if the drop database fails, otherwise it returns a string detailing the success 
     1449     */ 
     1450    public function dropDatabase() 
     1451    { 
    14181452      try { 
    1419           // Create database 
    1420           $connect->export->createDatabase($info['dbname']); 
    1421  
    1422           // Close the tmp connection with no database 
    1423           $manager->closeConnection($connect); 
    1424  
    1425           // Close original connection 
    1426           $manager->closeConnection($this); 
    1427  
    1428           // Reopen original connection with newly created database 
    1429           $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); 
    1430  
    1431           return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
    1432       } catch (Exception $e) { 
    1433           return $e; 
    1434       } 
    1435     } 
    1436  
    1437     /** 
    1438      * dropDatabase 
    1439      * 
    1440      * @return void 
    1441      */ 
    1442     public function dropDatabase() 
    1443     { 
    1444       try { 
    1445           $info = $this->getManager()->parsePdoDsn($this->getOption('dsn')); 
     1453          if ( ! $dsn = $this->getOption('dsn')) { 
     1454              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'); 
     1455          } 
     1456 
     1457          $info = $this->getManager()->parsePdoDsn($dsn); 
    14461458           
    14471459          $this->export->dropDatabase($info['dbname']); 
  • trunk/lib/Doctrine/Connection/Mysql.php

    r3458 r3566  
    9292 
    9393    /** 
    94      * returns the name of the connected database 
    95      * 
    96      * @return string 
    97      */ 
    98     public function getDatabaseName() 
    99     { 
    100         return $this->fetchOne('SELECT DATABASE()'); 
    101     } 
    102  
    103     /** 
    10494     * Set the charset on the current connection 
    10595     * 
  • trunk/lib/Doctrine/Connection/Sqlite.php

    r3565 r3566  
    104104    { 
    105105      try { 
    106           $manager = $this->getManager(); 
     106          if ( ! $dsn = $this->getOption('dsn')) { 
     107              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'); 
     108          } 
    107109 
    108           $info = $manager->parseDsn($this->getOption('dsn')); 
     110          $info = $this->getManager()->parseDsn($dsn); 
    109111 
    110112          $this->export->createDatabase($info['database']); 
     
    124126    { 
    125127      try { 
    126           $info = $this->getManager()->parseDsn($this->getOption('dsn')); 
     128          if ( ! $dsn = $this->getOption('dsn')) { 
     129              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'); 
     130          } 
     131           
     132          $info = $this->getManager()->parseDsn($dsn); 
    127133 
    128134          $this->export->dropDatabase($info['database']);