From 4d4374395bc057f6e3962b8b5bb0dc898c41af66 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Sat, 5 Sep 2009 02:23:24 +0000 Subject: [PATCH] [2.0] Added boolean type support --- .../DBAL/Platforms/AbstractPlatform.php | 13 +++--- lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php | 19 ++++++++- .../DBAL/Platforms/OraclePlatform.php | 8 ++++ .../DBAL/Platforms/PostgreSqlPlatform.php | 13 +++++- .../DBAL/Platforms/SqlitePlatform.php | 40 +++++++++++++++---- lib/Doctrine/DBAL/Types/BooleanType.php | 2 +- 6 files changed, 77 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index abb341105..55b7f41f8 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -769,6 +769,14 @@ abstract class AbstractPlatform return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')'; } + /** + * Gets the SQL snippet that declares a boolean column. + * + * @param array $columnDef + * @return string + */ + abstract public function getBooleanTypeDeclarationSql(array $columnDef); + /** * Gets the SQL snippet that declares a 4 byte integer column. * @@ -1543,11 +1551,6 @@ abstract class AbstractPlatform */ abstract public function getVarcharTypeDeclarationSql(array $field); - public function getBooleanTypeDeclarationSql(array $field) - { - return $this->getIntegerTypeDeclarationSql($field); - } - /** * Gets the name of the platform. * diff --git a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php index 265aa9004..c323fbf15 100644 --- a/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php @@ -324,19 +324,34 @@ class MsSqlPlatform extends AbstractPlatform { return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); } + + /** + * @override + */ + public function getBooleanTypeDeclarationSql(array $field) + { + return 'BIT'; + } + /** + * @override + */ public function getIntegerTypeDeclarationSql(array $field) { return 'INT' . $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getBigIntTypeDeclarationSql(array $field) { return 'BIGINT' . $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getSmallIntTypeDeclarationSql(array $field) { return 'SMALLINT' . $this->_getCommonIntegerTypeDeclarationSql($field); diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 5d0b27704..090b8e69b 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -152,6 +152,14 @@ class OraclePlatform extends AbstractPlatform return parent::_getTransactionIsolationLevelSql($level); } } + + /** + * @override + */ + public function getBooleanTypeDeclarationSql(array $field) + { + return 'NUMBER(1)'; + } /** * @override diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index aab0e0117..48aff9dcb 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -218,10 +218,10 @@ class PostgreSqlPlatform extends AbstractPlatform * @param string $value boolean value to be parsed * @return string parsed boolean value */ - public function parseBoolean($value) + /*public function parseBoolean($value) { return $value; - } + }*/ /** * Whether the platform supports sequences. @@ -656,6 +656,14 @@ class PostgreSqlPlatform extends AbstractPlatform return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSql($level); } + + /** + * @override + */ + public function getBooleanTypeDeclarationSql(array $field) + { + return 'BOOLEAN'; + } /** * @override @@ -665,6 +673,7 @@ class PostgreSqlPlatform extends AbstractPlatform if ( ! empty($field['autoincrement'])) { return 'SERIAL'; } + return 'INT'; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index c2b98894a..457008be6 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -193,43 +193,65 @@ class SqlitePlatform extends AbstractPlatform return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSql($level); } - /** @override */ + /** + * @override + */ public function prefersIdentityColumns() { return true; } + + /** + * @override + */ + public function getBooleanTypeDeclarationSql(array $field) + { + return 'BOOLEAN'; + } - /** @override */ + /** + * @override + */ public function getIntegerTypeDeclarationSql(array $field) { return $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getBigIntTypeDeclarationSql(array $field) { return $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getTinyIntTypeDeclarationSql(array $field) { return $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getSmallIntTypeDeclarationSql(array $field) { return $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getMediumIntTypeDeclarationSql(array $field) { return $this->_getCommonIntegerTypeDeclarationSql($field); } - /** @override */ + /** + * @override + */ public function getDateTimeTypeDeclarationSql(array $fieldDeclaration) { return 'DATETIME'; @@ -243,7 +265,9 @@ class SqlitePlatform extends AbstractPlatform return 'DATE'; } - /** @override */ + /** + * @override + */ protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) { $autoinc = ! empty($columnDef['autoincrement']) ? ' AUTOINCREMENT' : ''; diff --git a/lib/Doctrine/DBAL/Types/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php index 98b0a5b8d..ff05455d8 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -13,7 +13,7 @@ class BooleanType extends Type { public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - return $platform->getBooleanDeclarationSql(); + return $platform->getBooleanTypeDeclarationSql($fieldDeclaration); } public function convertToDatabaseValue($value, AbstractPlatform $platform)