From dc6442970b9c59c7fbce38fb33eeca619dcbba5e Mon Sep 17 00:00:00 2001 From: Daniel Chesterton Date: Thu, 18 Dec 2014 10:09:32 +0000 Subject: [PATCH 1/5] [DBAL-1082] Fix SchemaTool does not generate SQL for MySQL unsigned float --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 5ab8193f044..41d5dab3f4a 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -713,6 +713,14 @@ public function getSmallIntTypeDeclarationSQL(array $field) return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSQL($field); } + /** + * {@inheritdoc} + */ + public function getFloatDeclarationSQL(array $field) + { + return 'DOUBLE PRECISION' . $this->_getCommonIntegerTypeDeclarationSQL($field); + } + /** * {@inheritDoc} */ From 1e12336e34b3ad0c94a2f5c44693e5597df3aaea Mon Sep 17 00:00:00 2001 From: Daniel Chesterton Date: Thu, 18 Dec 2014 10:32:42 +0000 Subject: [PATCH 2/5] Add UNSIGNED generation for Decimal fields too --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 41d5dab3f4a..d35efb365f0 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -721,6 +721,15 @@ public function getFloatDeclarationSQL(array $field) return 'DOUBLE PRECISION' . $this->_getCommonIntegerTypeDeclarationSQL($field); } + /** + * {@inheritdoc} + */ + public function getDecimalTypeDeclarationSQL(array $columnDef) + { + $declaration = parent::getDecimalTypeDeclarationSQL($columnDef); + return $declaration . $this->_getCommonIntegerTypeDeclarationSQL($columnDef); + } + /** * {@inheritDoc} */ From 30f46c7006d345a4b7cc51281b171d0e2c5cb46b Mon Sep 17 00:00:00 2001 From: Daniel Chesterton Date: Thu, 18 Dec 2014 10:34:13 +0000 Subject: [PATCH 3/5] Update documentation for UNSIGNED float/decimal --- docs/en/reference/types.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/reference/types.rst b/docs/en/reference/types.rst index 1405990e32a..91d9778556e 100644 --- a/docs/en/reference/types.rst +++ b/docs/en/reference/types.rst @@ -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** | | | | | +--------------------------+ | | From eb374b5a090dfd340b7d41423e0320ed7ac6d35c Mon Sep 17 00:00:00 2001 From: Daniel Chesterton Date: Thu, 18 Dec 2014 11:02:18 +0000 Subject: [PATCH 4/5] Disallow AUTO_INCREMENT on decimal/float --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index d35efb365f0..aa9a0377cbe 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -718,7 +718,7 @@ public function getSmallIntTypeDeclarationSQL(array $field) */ public function getFloatDeclarationSQL(array $field) { - return 'DOUBLE PRECISION' . $this->_getCommonIntegerTypeDeclarationSQL($field); + return 'DOUBLE PRECISION' . $this->getUnsignedDeclaration($field); } /** @@ -727,7 +727,19 @@ public function getFloatDeclarationSQL(array $field) public function getDecimalTypeDeclarationSQL(array $columnDef) { $declaration = parent::getDecimalTypeDeclarationSQL($columnDef); - return $declaration . $this->_getCommonIntegerTypeDeclarationSQL($columnDef); + return $declaration . $this->getUnsignedDeclaration($columnDef); + } + + /** + * Get unsigned declaration for a column. + * + * @param array $columnDef + * + * @return string + */ + private function getUnsignedDeclaration(array $columnDef) + { + return (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : ''; } /** @@ -739,9 +751,8 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) if ( ! empty($columnDef['autoincrement'])) { $autoinc = ' AUTO_INCREMENT'; } - $unsigned = (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : ''; - return $unsigned . $autoinc; + return $this->getUnsignedDeclaration($columnDef) . $autoinc; } /** From 68542739f788ec38b89efc17517e52963f117a79 Mon Sep 17 00:00:00 2001 From: Daniel Chesterton Date: Thu, 18 Dec 2014 11:20:11 +0000 Subject: [PATCH 5/5] Simplify getUnsignedDeclaration --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index aa9a0377cbe..ce8c3bec7c4 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -739,7 +739,7 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) */ private function getUnsignedDeclaration(array $columnDef) { - return (isset($columnDef['unsigned']) && $columnDef['unsigned']) ? ' UNSIGNED' : ''; + return ! empty($columnDef['unsigned']) ? ' UNSIGNED' : ''; } /**