Commit d5c91081 authored by jwage's avatar jwage

-

parent 689a4c6f
...@@ -1402,47 +1402,59 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1402,47 +1402,59 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
/** /**
* createDatabase * createDatabase
* *
* @return void * 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
*/ */
public function createDatabase() public function createDatabase()
{ {
$manager = $this->getManager(); try {
if ( ! $dsn = $this->getOption('dsn')) {
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');
}
$info = $manager->parsePdoDsn($this->getOption('dsn')); $manager = $this->getManager();
$username = $this->getOption('username');
$password = $this->getOption('password');
// Make connection without database specified so we can create it $info = $manager->parsePdoDsn($dsn);
$connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); $username = $this->getOption('username');
$password = $this->getOption('password');
try {
// Create database
$connect->export->createDatabase($info['dbname']);
// Close the tmp connection with no database // Make connection without database specified so we can create it
$manager->closeConnection($connect); $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false);
// Close original connection // Create database
$manager->closeConnection($this); $connect->export->createDatabase($info['dbname']);
// Reopen original connection with newly created database // Close the tmp connection with no database
$manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); $manager->closeConnection($connect);
return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; // Close original connection
} catch (Exception $e) { $manager->closeConnection($this);
return $e;
} // Reopen original connection with newly created database
$manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true);
return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"';
} catch (Exception $e) {
return $e;
}
} }
/** /**
* dropDatabase * dropDatabase
* *
* @return void * 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
*/ */
public function dropDatabase() public function dropDatabase()
{ {
try { try {
$info = $this->getManager()->parsePdoDsn($this->getOption('dsn')); if ( ! $dsn = $this->getOption('dsn')) {
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');
}
$info = $this->getManager()->parsePdoDsn($dsn);
$this->export->dropDatabase($info['dbname']); $this->export->dropDatabase($info['dbname']);
...@@ -1460,4 +1472,4 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -1460,4 +1472,4 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
{ {
return Doctrine_Lib::getConnectionAsString($this); return Doctrine_Lib::getConnectionAsString($this);
} }
} }
\ No newline at end of file
...@@ -90,16 +90,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common ...@@ -90,16 +90,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
parent::__construct($manager, $adapter); parent::__construct($manager, $adapter);
} }
/**
* returns the name of the connected database
*
* @return string
*/
public function getDatabaseName()
{
return $this->fetchOne('SELECT DATABASE()');
}
/** /**
* Set the charset on the current connection * Set the charset on the current connection
* *
......
...@@ -103,9 +103,11 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common ...@@ -103,9 +103,11 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
public function createDatabase() public function createDatabase()
{ {
try { try {
$manager = $this->getManager(); if ( ! $dsn = $this->getOption('dsn')) {
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');
}
$info = $manager->parseDsn($this->getOption('dsn')); $info = $this->getManager()->parseDsn($dsn);
$this->export->createDatabase($info['database']); $this->export->createDatabase($info['database']);
...@@ -123,7 +125,11 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common ...@@ -123,7 +125,11 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common
public function dropDatabase() public function dropDatabase()
{ {
try { try {
$info = $this->getManager()->parseDsn($this->getOption('dsn')); if ( ! $dsn = $this->getOption('dsn')) {
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');
}
$info = $this->getManager()->parseDsn($dsn);
$this->export->dropDatabase($info['database']); $this->export->dropDatabase($info['database']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment