Commit e3441215 authored by Steve Müller's avatar Steve Müller

Merge pull request #749 from dchesterton/master

[DBAL-1082] Fix SchemaTool does not generate SQL for MySQL unsigned float

Close #749
parents c1eae738 5d74b25a
......@@ -469,9 +469,9 @@ Please also notice the mapping specific footnotes for additional information.
| | +--------------------------+---------+----------------------------------------------------------+
| | | **SQLite** | *all* | ``INTEGER`` [16]_ |
+-------------------+---------------+--------------------------+---------+----------------------------------------------------------+
| **decimal** [7]_ | ``string`` | **MySQL** | *all* | ``NUMERIC(p, s)`` |
| | [9]_ +--------------------------+ | |
| | | **PostgreSQL** | | |
| **decimal** [7]_ | ``string`` | **MySQL** | *all* | ``NUMERIC(p, s)`` ``UNSIGNED`` [10]_ |
| | [9]_ +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``NUMERIC(p, s)`` |
| | +--------------------------+ | |
| | | **Oracle** | | |
| | +--------------------------+ | |
......@@ -483,9 +483,9 @@ Please also notice the mapping specific footnotes for additional information.
| | +--------------------------+ | |
| | | **Drizzle** | | |
+-------------------+---------------+--------------------------+---------+----------------------------------------------------------+
| **float** | ``float`` | **MySQL** | *all* | ``DOUBLE PRECISION`` |
| | +--------------------------+ | |
| | | **PostgreSQL** | | |
| **float** | ``float`` | **MySQL** | *all* | ``DOUBLE PRECISION`` ``UNSIGNED`` [10]_ |
| | +--------------------------+---------+----------------------------------------------------------+
| | | **PostgreSQL** | *all* | ``DOUBLE PRECISION`` |
| | +--------------------------+ | |
| | | **Oracle** | | |
| | +--------------------------+ | |
......
......@@ -804,6 +804,34 @@ class MySqlPlatform extends AbstractPlatform
return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field);
}
/**
* {@inheritdoc}
*/
public function getFloatDeclarationSQL(array $field)
{
return 'DOUBLE PRECISION' . $this->getUnsignedDeclaration($field);
}
/**
* {@inheritdoc}
*/
public function getDecimalTypeDeclarationSQL(array $columnDef)
{
return parent::getDecimalTypeDeclarationSQL($columnDef) . $this->getUnsignedDeclaration($columnDef);
}
/**
* Get unsigned declaration for a column.
*
* @param array $columnDef
*
* @return string
*/
private function getUnsignedDeclaration(array $columnDef)
{
return ! empty($columnDef['unsigned']) ? ' UNSIGNED' : '';
}
/**
* {@inheritDoc}
*/
......@@ -813,9 +841,8 @@ class MySqlPlatform extends AbstractPlatform
if ( ! empty($columnDef['autoincrement'])) {
$autoinc = ' AUTO_INCREMENT';
}
$unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : '';
return $unsigned . $autoinc;
return $this->getUnsignedDeclaration($columnDef) . $autoinc;
}
/**
......
......@@ -279,4 +279,46 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
"No differences should be detected with the offline vs online schema."
);
}
/**
* @group DBAL-1082
*/
public function testListDecimalTypeColumns()
{
$tableName = 'test_list_decimal_columns';
$table = new Table($tableName);
$table->addColumn('col', 'decimal');
$table->addColumn('col_unsigned', 'decimal', array('unsigned' => true));
$this->_sm->dropAndCreateTable($table);
$columns = $this->_sm->listTableColumns($tableName);
$this->assertArrayHasKey('col', $columns);
$this->assertArrayHasKey('col_unsigned', $columns);
$this->assertFalse($columns['col']->getUnsigned());
$this->assertTrue($columns['col_unsigned']->getUnsigned());
}
/**
* @group DBAL-1082
*/
public function testListFloatTypeColumns()
{
$tableName = 'test_list_float_columns';
$table = new Table($tableName);
$table->addColumn('col', 'float');
$table->addColumn('col_unsigned', 'float', array('unsigned' => true));
$this->_sm->dropAndCreateTable($table);
$columns = $this->_sm->listTableColumns($tableName);
$this->assertArrayHasKey('col', $columns);
$this->assertArrayHasKey('col_unsigned', $columns);
$this->assertFalse($columns['col']->getUnsigned());
$this->assertTrue($columns['col_unsigned']->getUnsigned());
}
}
......@@ -680,4 +680,34 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)',
);
}
/**
* {@inheritdoc}
*/
public function getGeneratesDecimalTypeDeclarationSQL()
{
return array(
array(array(), 'NUMERIC(10, 0)'),
array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'),
array(array('unsigned' => false), 'NUMERIC(10, 0)'),
array(array('precision' => 5), 'NUMERIC(5, 0)'),
array(array('scale' => 5), 'NUMERIC(10, 5)'),
array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'),
);
}
/**
* {@inheritdoc}
*/
public function getGeneratesFloatDeclarationSQL()
{
return array(
array(array(), 'DOUBLE PRECISION'),
array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'),
array(array('unsigned' => false), 'DOUBLE PRECISION'),
array(array('precision' => 5), 'DOUBLE PRECISION'),
array(array('scale' => 5), 'DOUBLE PRECISION'),
array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'),
);
}
}
......@@ -1192,4 +1192,54 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
* @return array
*/
abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL();
/**
* @group DBAL-1082
*
* @dataProvider getGeneratesDecimalTypeDeclarationSQL
*/
public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql)
{
$this->assertSame($expectedSql, $this->_platform->getDecimalTypeDeclarationSQL($column));
}
/**
* @return array
*/
public function getGeneratesDecimalTypeDeclarationSQL()
{
return array(
array(array(), 'NUMERIC(10, 0)'),
array(array('unsigned' => true), 'NUMERIC(10, 0)'),
array(array('unsigned' => false), 'NUMERIC(10, 0)'),
array(array('precision' => 5), 'NUMERIC(5, 0)'),
array(array('scale' => 5), 'NUMERIC(10, 5)'),
array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'),
);
}
/**
* @group DBAL-1082
*
* @dataProvider getGeneratesFloatDeclarationSQL
*/
public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql)
{
$this->assertSame($expectedSql, $this->_platform->getFloatDeclarationSQL($column));
}
/**
* @return array
*/
public function getGeneratesFloatDeclarationSQL()
{
return array(
array(array(), 'DOUBLE PRECISION'),
array(array('unsigned' => true), 'DOUBLE PRECISION'),
array(array('unsigned' => false), 'DOUBLE PRECISION'),
array(array('precision' => 5), 'DOUBLE PRECISION'),
array(array('scale' => 5), 'DOUBLE PRECISION'),
array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'),
);
}
}
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