Commit 77dbcac3 authored by beberlei's avatar beberlei

Fixed a problem in PostgreSql AutoIncrement Detection, changed Autoincrement...

Fixed a problem in PostgreSql AutoIncrement Detection, changed Autoincrement API for platform/schema manager interaction a little bit
parent 07de0dd8
......@@ -217,7 +217,8 @@ abstract class AbstractSchemaManager
$idGeneratorType = Table::ID_NONE;
foreach ($columns AS $column) {
if ($column->hasPlatformOption('autoincrement') && $column->getPlatformOption('autoincrement')) {
/* @var $column Column */
if ($column->getAutoincrement()) {
$idGeneratorType = Table::ID_IDENTITY;
}
}
......
......@@ -312,7 +312,7 @@ class Column extends AbstractAsset
public function setAutoincrement($flag)
{
$this->_autoincrement = (bool)$flag;
$this->_autoincrement = $flag;
return $this;
}
......
......@@ -153,11 +153,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
'notnull' => (bool) ($tableColumn['Null'] != 'YES'),
'scale' => null,
'precision' => null,
'platformOptions' => array(
'primary' => (strtolower($tableColumn['Key']) == 'pri') ? true : false,
'unique' => (strtolower($tableColumn['Key']) == 'uni') ? true :false,
'autoincrement' => (bool) (strpos($tableColumn['Extra'], 'auto_increment') !== false),
),
'autoincrement' => (bool) (strpos($tableColumn['Extra'], 'auto_increment') !== false),
);
if ($scale !== null && $precision !== null) {
......
......@@ -170,10 +170,12 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
}
$matches = array();
$autoincrement = false;
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) {
$tableColumn['sequence'] = $matches[1];
$tableColumn['default'] = null;
$autoincrement = true;
}
if (stripos($tableColumn['default'], 'NULL') !== null) {
......@@ -200,25 +202,16 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$dbType = strtolower($tableColumn['type']);
$type = $this->_platform->getDoctrineTypeMapping($dbType);
$autoincrement = false;
switch ($dbType) {
case 'smallint':
case 'int2':
$length = null;
break;
case 'serial':
case 'serial4':
$autoincrement = true;
// break missing intentionally
case 'int':
case 'int4':
case 'integer':
$length = null;
break;
case 'bigserial':
case 'serial8':
$autoincrement = true;
// break missing intentionally
case 'bigint':
case 'int8':
$length = null;
......@@ -268,9 +261,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
'scale' => $scale,
'fixed' => $fixed,
'unsigned' => false,
'platformDetails' => array(
'autoincrement' => $autoincrement,
),
'autoincrement' => $autoincrement,
);
return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
......
......@@ -168,9 +168,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
'default' => $default,
'precision' => $precision,
'scale' => $scale,
'platformDetails' => array(
'autoincrement' => (bool) $tableColumn['pk'],
),
'autoincrement' => (bool) $tableColumn['pk'],
);
return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
......
......@@ -359,6 +359,27 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$views = $this->_sm->listViews();
}
public function testAutoincrementDetection()
{
if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
$this->markTestSkipped('This test is only supported on platforms that have autoincrement');
}
$table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
$table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY);
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->setPrimaryKey(array('id'));
$this->_sm->createTable($table);
$inferredTable = $this->_sm->listTableDetails('test_autoincrement');
$this->assertTrue($inferredTable->hasColumn('id'));
$this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
}
protected function createTestTable($name = 'test_table', $data = array())
{
$options = array();
......
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