Changeset 3967

Show
Ignore:
Timestamp:
03/11/08 02:51:33 (16 months ago)
Author:
jwage
Message:

fixes #848

Location:
branches/0.10/lib/Doctrine
Files:
5 modified

Legend:

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

    r3914 r3967  
    13801380    public function createDatabase() 
    13811381    { 
     1382        if ( ! $dsn = $this->getOption('dsn')) { 
     1383            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'); 
     1384        } 
     1385 
    13821386        try { 
    1383             if ( ! $dsn = $this->getOption('dsn')) { 
    1384                 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'); 
    1385             } 
    1386  
    1387             $manager = $this->getManager(); 
    1388  
    1389             $info = $manager->parsePdoDsn($dsn); 
    1390             $username = $this->getOption('username'); 
    1391             $password = $this->getOption('password'); 
    1392  
    1393             // Make connection without database specified so we can create it 
    1394             $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
    1395  
    1396             // Create database 
     1387            // Parse pdo dsn so we are aware of the connection information parts 
     1388            $info = $this->getManager()->parsePdoDsn($dsn); 
     1389 
     1390            // Get the temporary connection to issue the drop database command 
     1391            $connect = $this->getTmpConnection($info); 
     1392 
     1393            // Issue create database command 
    13971394            $connect->export->createDatabase($info['dbname']); 
    13981395 
    1399             // Close the tmp connection with no database 
    1400             $manager->closeConnection($connect); 
    1401  
    1402             // Close original connection 
    1403             $manager->closeConnection($this); 
    1404  
    1405             // Reopen original connection with newly created database 
    1406             $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); 
     1396            // Close the temporary connection used to issue the drop database command 
     1397            $this->getManager()->closeConnection($connect); 
     1398 
     1399            // Close original 
     1400            $this->getManager()->closeConnection($this); 
     1401 
     1402            // Re-open connection with the newly created database 
     1403            $this->getManager()->openConnection(new PDO($dsn, $this->getOption('username'), $this->getOption('password')), $this->getName(), true); 
    14071404 
    14081405            return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     
    14211418    public function dropDatabase() 
    14221419    { 
    1423       try { 
    1424           if ( ! $dsn = $this->getOption('dsn')) { 
    1425               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'); 
    1426           } 
    1427  
    1428           $info = $this->getManager()->parsePdoDsn($dsn); 
    1429  
    1430           $this->export->dropDatabase($info['dbname']); 
    1431  
    1432           return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
    1433       } catch (Exception $e) { 
    1434           return $e; 
    1435       } 
     1420        if ( ! $dsn = $this->getOption('dsn')) { 
     1421            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'); 
     1422        } 
     1423 
     1424        try { 
     1425            // Parse pdo dsn so we are aware of the connection information parts 
     1426            $info = $this->getManager()->parsePdoDsn($dsn); 
     1427 
     1428            // Get the temporary connection to issue the drop database command 
     1429            $connect = $this->getTmpConnection($info); 
     1430 
     1431            // Issue drop database command 
     1432            $connect->export->dropDatabase($info['dbname']); 
     1433 
     1434            // Close the temporary connection used to issue the drop database command 
     1435            $this->getManager()->closeConnection($connect); 
     1436 
     1437            return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1438        } catch (Exception $e) { 
     1439            return $e; 
     1440        } 
     1441    } 
     1442 
     1443    /** 
     1444     * getTmpConnection 
     1445     * 
     1446     * @param string $info  
     1447     * @return void 
     1448     */ 
     1449    public function getTmpConnection($info) 
     1450    { 
     1451        $pdoDsn = $info['scheme'] . ':host=' . $info['host']; 
     1452 
     1453        if (isset($this->export->tmpConnectionDatabase) && $this->export->tmpConnectionDatabase) { 
     1454            $pdoDsn .= ';dbname=' . $this->export->tmpConnectionDatabase; 
     1455        } 
     1456 
     1457        $username = $this->getOption('username'); 
     1458        $password = $this->getOption('password'); 
     1459 
     1460        return $this->getManager()->openConnection(new PDO($pdoDsn, $username, $password), 'doctrine_tmp_connection', false); 
    14361461    } 
    14371462 
  • branches/0.10/lib/Doctrine/Export/Mysql.php

    r3884 r3967  
    3434class Doctrine_Export_Mysql extends Doctrine_Export 
    3535{ 
    36    /** 
    37      * create a new database 
    38      * 
    39      * @param string $name name of the database that should be created 
    40      * @return string 
     36    /** 
     37     * createDatabaseSql 
     38     * 
     39     * @param string $name  
     40     * @return void 
    4141     */ 
    4242    public function createDatabaseSql($name) 
  • branches/0.10/lib/Doctrine/Export/Pgsql.php

    r3884 r3967  
    3434class Doctrine_Export_Pgsql extends Doctrine_Export 
    3535{ 
    36    /** 
    37      * create a new database 
    38      * 
    39      * @param string $name name of the database that should be created 
    40      * @throws PDOException 
     36    public $tmpConnectionDatabase = 'postgres'; 
     37 
     38    /** 
     39     * createDatabaseSql 
     40     * 
     41     * @param string $name  
    4142     * @return void 
    4243     */ 
  • branches/0.10/lib/Doctrine/Export/Sqlite.php

    r3884 r3967  
    8989     *                                 drivers of those that do not support it ignore this property. Use the 
    9090     *                                 function support() to determine whether the DBMS driver can manage indexes. 
    91  
    9291     *                                 Example 
    9392     *                                    array( 
     
    220219            } 
    221220        } 
     221 
    222222        return $query; 
    223          
    224          
    225         /** 
    226         try { 
    227  
    228             if ( ! empty($fk)) { 
    229                 $this->conn->beginTransaction(); 
    230             } 
    231  
    232             $ret   = $this->conn->exec($query); 
    233  
    234             if ( ! empty($fk)) { 
    235                 foreach ($fk as $definition) { 
    236  
    237                     $query = 'CREATE TRIGGER doctrine_' . $name . '_cscd_delete ' 
    238                            . 'AFTER DELETE ON ' . $name . ' FOR EACH ROW ' 
    239                            . 'BEGIN ' 
    240                            . 'DELETE FROM ' . $definition['foreignTable'] . ' WHERE '; 
    241  
    242                     $local = (array) $definition['local']; 
    243                     foreach((array) $definition['foreign'] as $k => $field) { 
    244                         $query .= $field . ' = old.' . $local[$k] . ';'; 
    245                     } 
    246  
    247                     $query .= 'END;'; 
    248  
    249                     $this->conn->exec($query); 
    250                 } 
    251  
    252                 $this->conn->commit(); 
    253             } 
    254  
    255  
    256         } catch(Doctrine_Exception $e) { 
    257  
    258             $this->conn->rollback(); 
    259  
    260             throw $e; 
    261         } 
    262         */ 
    263223    } 
    264224 
  • branches/0.10/lib/Doctrine/Manager.php

    r3953 r3967  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
    21  
     21Doctrine::autoload('Doctrine_Configurable'); 
    2222/** 
    2323 * 
     
    704704 
    705705        foreach ($this as $name => $connection) { 
    706             if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
     706            if ( ! empty($specifiedConnections) && ! in_array($name, $specifiedConnections)) { 
    707707                continue; 
    708708            } 
     
    732732 
    733733        foreach ($this as $name => $connection) { 
    734             if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
     734            if ( ! empty($specifiedConnections) && ! in_array($name, $specifiedConnections)) { 
    735735                continue; 
    736736            }