Commit ac8492d2 authored by romanb's avatar romanb

[2.0] DBAL code cleanups.

parent 9586b748
......@@ -195,19 +195,9 @@ class MsSqlSchemaManager extends AbstractSchemaManager
}
/**
* 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
* {@inheritdoc}
*/
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);
$seqcolName = $this->conn->quoteIdentifier($this->conn->options['seqcol_name'], true);
......
......@@ -293,14 +293,18 @@ class MySqlSchemaManager extends AbstractSchemaManager
);
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);
$seqcolName = $this->_conn->quoteIdentifier($this->_conn->getAttribute(Doctrine::ATTR_SEQCOL_NAME), true);
$sequenceName = $this->_conn->quoteIdentifier($sequenceName);
$seqColumnName = 'mysql_sequence';
/* No support for options yet. Might add 4th options parameter later
$optionsStrings = array();
if (isset($options['comment']) && ! empty($options['comment'])) {
$optionsStrings['comment'] = 'COMMENT = ' . $this->_conn->quote($options['comment'], 'string');
}
......@@ -312,7 +316,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$optionsStrings['collate'] .= ' COLLATE ' . $options['collate'];
}
}
$type = false;
if (isset($options['type'])) {
......@@ -322,38 +326,39 @@ class MySqlSchemaManager extends AbstractSchemaManager
}
if ($type) {
$optionsStrings[] = 'ENGINE = ' . $type;
}
}*/
try {
$query = 'CREATE TABLE ' . $sequenceName
. ' (' . $seqcolName . ' INT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
. $seqcolName . '))';
if (!empty($options_strings)) {
/*if (!empty($options_strings)) {
$query .= ' '.implode(' ', $options_strings);
}
}*/
$query .= ' ENGINE = INNODB';
$res = $this->_conn->exec($query);
$res = $this->_conn->exec($query);
} catch(Doctrine\DBAL\ConnectionException $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table');
}
if ($start == 1) {
return true;
}
return;
}
$query = 'INSERT INTO ' . $sequenceName
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
$res = $this->_conn->exec($query);
// Handle error
try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch(Doctrine\DBAL\ConnectionException $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table');
}
$res = $this->_conn->exec($query);
return $res;
// Handle error
try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch (\Exception $e) {
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table');
}
return $res;
}
}
\ No newline at end of file
......@@ -239,53 +239,22 @@ class OracleSchemaManager extends AbstractSchemaManager
{
try {
$this->dropAutoincrement($name);
} catch (\Exception $e) {}
} catch (\Exception $e) {
//FIXME: Exception silencing ;'-(
}
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
* @return array
*/
public function listSequences($database = null)
{
//FIXME: $database not used. Remove?
$query = "SELECT sequence_name FROM sys.user_sequences";
$tableNames = $this->_conn->fetchColumn($query);
......
......@@ -33,21 +33,26 @@ namespace Doctrine\DBAL\Schema;
*/
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)) {
unlink($database);
}
}
public function createDatabase($database = null)
/**
* {@inheritdoc}
*
* @override
*/
public function createDatabase($database)
{
if (is_null($database)) {
$database = $this->_conn->getDatabase();
}
// FIXME: $database parameter not used
// TODO: Can we do this better?
$this->_conn->close();
$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