Commit ac8492d2 authored by romanb's avatar romanb

[2.0] DBAL code cleanups.

parent 9586b748
...@@ -195,19 +195,9 @@ class MsSqlSchemaManager extends AbstractSchemaManager ...@@ -195,19 +195,9 @@ class MsSqlSchemaManager extends AbstractSchemaManager
} }
/** /**
* create sequence * {@inheritdoc}
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* );
* @return string
*/ */
public function createSequence($seqName, $start = 1, array $options = array()) public function createSequence($seqName, $start = 1, $allocationSize = 1)
{ {
$sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true); $sequenceName = $this->conn->quoteIdentifier($this->conn->getSequenceName($seqName), true);
$seqcolName = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true); $seqcolName = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true);
......
...@@ -294,11 +294,15 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -294,11 +294,15 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $foreignKey; return $foreignKey;
} }
public function createSequence($sequenceName, $start = 1, array $options = array()) /**
* {@inheritdoc}
*/
public function createSequence($sequenceName, $start = 1, $allocationSize = 1)
{ {
$sequenceName = $this->_conn->quoteIdentifier($this->_conn->getSequenceName($sequenceName), true); $sequenceName = $this->_conn->quoteIdentifier($sequenceName);
$seqcolName = $this->_conn->quoteIdentifier($this->_conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true); $seqColumnName = 'mysql_sequence';
/* No support for options yet. Might add 4th options parameter later
$optionsStrings = array(); $optionsStrings = array();
if (isset($options['comment']) && ! empty($options['comment'])) { if (isset($options['comment']) && ! empty($options['comment'])) {
...@@ -322,16 +326,17 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -322,16 +326,17 @@ class MySqlSchemaManager extends AbstractSchemaManager
} }
if ($type) { if ($type) {
$optionsStrings[] = 'ENGINE = ' . $type; $optionsStrings[] = 'ENGINE = ' . $type;
} }*/
try { try {
$query = 'CREATE TABLE ' . $sequenceName $query = 'CREATE TABLE ' . $sequenceName
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (' . ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcolName . '))'; . $seqcolName . '))';
if (!empty($options_strings)) { /*if (!empty($options_strings)) {
$query .= ' '.implode(' ', $options_strings); $query .= ' '.implode(' ', $options_strings);
} }*/
$query .= ' ENGINE = INNODB';
$res = $this->_conn->exec($query); $res = $this->_conn->exec($query);
} catch(Doctrine\DBAL\ConnectionException $e) { } catch(Doctrine\DBAL\ConnectionException $e) {
...@@ -339,7 +344,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -339,7 +344,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
} }
if ($start == 1) { if ($start == 1) {
return true; return;
} }
$query = 'INSERT INTO ' . $sequenceName $query = 'INSERT INTO ' . $sequenceName
...@@ -350,7 +355,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -350,7 +355,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
// Handle error // Handle error
try { try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName); $res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch(Doctrine\DBAL\ConnectionException $e) { } catch (\Exception $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table'); throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table');
} }
......
...@@ -239,53 +239,22 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -239,53 +239,22 @@ class OracleSchemaManager extends AbstractSchemaManager
{ {
try { try {
$this->dropAutoincrement($name); $this->dropAutoincrement($name);
} catch (\Exception $e) {} } catch (\Exception $e) {
//FIXME: Exception silencing ;'-(
return parent::dropTable($name);
} }
/** return parent::dropTable($name);
* create sequence
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* );
* @return string
*/
public function createSequenceSql($seqName, $start = 1, array $options = array())
{
$sequenceName = $this->_conn->quoteIdentifier($this->_conn->formatter->getSequenceName($seqName), true);
$query = 'CREATE SEQUENCE ' . $sequenceName . ' START WITH ' . $start . ' INCREMENT BY 1 NOCACHE';
$query .= ($start < 1 ? ' MINVALUE ' . $start : '');
return $query;
}
/**
* drop existing sequence
*
* @param object $this->_conn database object that is extended by this class
* @param string $seqName name of the sequence to be dropped
* @return string
*/
public function dropSequenceSql($seqName)
{
$sequenceName = $this->_conn->quoteIdentifier($this->_conn->formatter->getSequenceName($seqName), true);
return 'DROP SEQUENCE ' . $sequenceName;
} }
/** /**
* lists all database sequences * Lists all sequences.
* *
* @param string|null $database * @param string|null $database
* @return array * @return array
*/ */
public function listSequences($database = null) public function listSequences($database = null)
{ {
//FIXME: $database not used. Remove?
$query = "SELECT sequence_name FROM sys.user_sequences"; $query = "SELECT sequence_name FROM sys.user_sequences";
$tableNames = $this->_conn->fetchColumn($query); $tableNames = $this->_conn->fetchColumn($query);
......
...@@ -33,21 +33,26 @@ namespace Doctrine\DBAL\Schema; ...@@ -33,21 +33,26 @@ namespace Doctrine\DBAL\Schema;
*/ */
class SqliteSchemaManager extends AbstractSchemaManager class SqliteSchemaManager extends AbstractSchemaManager
{ {
public function dropDatabase($database = null) /**
* {@inheritdoc}
*
* @override
*/
public function dropDatabase($database)
{ {
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
if (file_exists($database)) { if (file_exists($database)) {
unlink($database); unlink($database);
} }
} }
public function createDatabase($database = null) /**
* {@inheritdoc}
*
* @override
*/
public function createDatabase($database)
{ {
if (is_null($database)) { // FIXME: $database parameter not used
$database = $this->_conn->getDatabase();
}
// TODO: Can we do this better? // TODO: Can we do this better?
$this->_conn->close(); $this->_conn->close();
$this->_conn->connect(); $this->_conn->connect();
......
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