diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 49fdd2f99..d6c0d9ad9 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -41,6 +41,17 @@ class Doctrine_Export extends Doctrine_Connection_Module * @return void */ public function dropDatabase($database) + { + $this->conn->execute($this->dropDatabaseSql($database)); + } + /** + * drop an existing database + * (this method is implemented by the drivers) + * + * @param string $name name of the database that should be dropped + * @return void + */ + public function dropDatabaseSql($database) { throw new Doctrine_Export_Exception('Drop database not supported by this driver.'); } @@ -128,6 +139,17 @@ class Doctrine_Export extends Doctrine_Connection_Module * @return void */ public function createDatabase($database) + { + $this->conn->execute($this->createDatabaseSql($database)); + } + /** + * create a new database + * (this method is implemented by the drivers) + * + * @param string $name name of the database that should be created + * @return string + */ + public function createDatabaseSql($database) { throw new Doctrine_Export_Exception('Create database not supported by this driver.'); } @@ -170,13 +192,7 @@ class Doctrine_Export extends Doctrine_Connection_Module } $queryFields = $this->getFieldDeclarationList($fields); - /** - if (isset($options['foreignKeys']) && ! empty($options['foreignKeys'])) { - foreach($options['foreignKeys'] as $definition) { - $queryFields .= ', ' . $this->getForeignKeyDeclaration($definition); - } - } - */ + if (isset($options['primary']) && ! empty($options['primary'])) { $queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; diff --git a/lib/Doctrine/Export/Mysql.php b/lib/Doctrine/Export/Mysql.php index 5349cf1d0..a018235a7 100644 --- a/lib/Doctrine/Export/Mysql.php +++ b/lib/Doctrine/Export/Mysql.php @@ -37,25 +37,21 @@ class Doctrine_Export_Mysql extends Doctrine_Export * create a new database * * @param string $name name of the database that should be created - * @throws PDOException - * @return void + * @return string */ - public function createDatabase($name) + public function createDatabaseSql($name) { - $query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true); - $result = $this->conn->exec($query); + return 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name, true); } /** * drop an existing database * * @param string $name name of the database that should be dropped - * @throws PDOException - * @access public + * @return string */ - public function dropDatabase($name) + public function dropDatabaseSql($name) { - $query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); - $this->conn->exec($query); + return 'DROP DATABASE ' . $this->conn->quoteIdentifier($name); } /** * create a new table @@ -147,18 +143,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export } } - if (isset($options['foreignKeys']) && ! empty($options['foreignKeys'])) { - foreach($options['foreignKeys'] as $definition) { - $queryFields .= ', ' . $this->getForeignKeyDeclaration($definition); - } - } - if (isset($options['primary']) && ! empty($options['primary'])) { $queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; } - - $name = $this->conn->quoteIdentifier($name, true); $query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; @@ -612,10 +600,10 @@ class Doctrine_Export_Mysql extends Doctrine_Export $query .= ' MATCH ' . $definition['match']; } if (!empty($definition['onUpdate'])) { - $query .= ' ON UPDATE ' . $this->getForeignKeyRefentialAction($definition['onUpdate']); + $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialAction($definition['onUpdate']); } if (!empty($definition['onDelete'])) { - $query .= ' ON DELETE ' . $this->getForeignKeyRefentialAction($definition['onDelete']); + $query .= ' ON DELETE ' . $this->getForeignKeyReferentialAction($definition['onDelete']); } return $query; } diff --git a/lib/Doctrine/Export/Sqlite.php b/lib/Doctrine/Export/Sqlite.php index fb9b7b55b..bd2bd8f11 100644 --- a/lib/Doctrine/Export/Sqlite.php +++ b/lib/Doctrine/Export/Sqlite.php @@ -201,11 +201,13 @@ class Doctrine_Export_Sqlite extends Doctrine_Export $query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; try { + /** if ( ! empty($fk)) { $this->conn->beginTransaction(); } + */ $ret = $this->conn->exec($query); - + /** if ( ! empty($fk)) { foreach ($fk as $definition) { @@ -226,6 +228,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export $this->conn->commit(); } + */ } catch(Doctrine_Exception $e) { $this->conn->rollback();