From 9df8e4d0e399ed046c68d5c643596a1499cb6de8 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 28 Nov 2006 18:39:57 +0000 Subject: [PATCH] small fixes for datadict drivers --- lib/Doctrine/DataDict/Firebird.php | 19 +++++-- lib/Doctrine/DataDict/Mssql.php | 88 ++++++++++++++++-------------- 2 files changed, 60 insertions(+), 47 deletions(-) diff --git a/lib/Doctrine/DataDict/Firebird.php b/lib/Doctrine/DataDict/Firebird.php index b1e9826d0..4cd1f68b4 100644 --- a/lib/Doctrine/DataDict/Firebird.php +++ b/lib/Doctrine/DataDict/Firebird.php @@ -53,12 +53,19 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module { * @return string DBMS specific SQL code portion that should be used to * declare the specified field. */ - public function getTypeDeclaration($field) { - switch ($field['type']) { + public function getNativeDeclaration($field) { + switch($field['type']) { + case 'varchar': + case 'string': + case 'array': + case 'object': + case 'char': case 'text': $length = !empty($field['length']) - ? $field['length'] : $db->options['default_text_field_length']; - $fixed = !empty($field['fixed']) ? $field['fixed'] : false; + ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length']; + + $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; + return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')'; case 'clob': return 'BLOB SUB_TYPE 1'; @@ -83,12 +90,12 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module { return ''; } /** - * Maps a native array description of a field to a MDB2 datatype and length + * Maps a native array description of a field to a Doctrine datatype and length * * @param array $field native field description * @return array containing the various possible types, length, sign, fixed */ - public function mapNativeDatatype($field) { + public function getPortableDeclaration($field) { $length = $field['length']; if((int) $length <= 0) diff --git a/lib/Doctrine/DataDict/Mssql.php b/lib/Doctrine/DataDict/Mssql.php index 5033c48ea..a5fab2ed4 100644 --- a/lib/Doctrine/DataDict/Mssql.php +++ b/lib/Doctrine/DataDict/Mssql.php @@ -50,49 +50,56 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { * notnull * Boolean flag that indicates whether this field is constrained * to not be set to null. - * @author Lukas Smith (PEAR MDB2 library) + * * @return string DBMS specific SQL code portion that should be used to * declare the specified field. */ - public function getTypeDeclaration($field) { + public function getNativeDeclaration($field) { switch ($field['type']) { - case 'text': - $length = !empty($field['length']) - ? $field['length'] : false; - $fixed = !empty($field['fixed']) ? $field['fixed'] : false; - return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') - : ($length ? 'VARCHAR('.$length.')' : 'TEXT'); - case 'clob': - if (!empty($field['length'])) { - $length = $field['length']; - if ($length <= 8000) { - return 'VARCHAR('.$length.')'; + case 'array': + case 'object': + case 'text': + case 'char': + case 'varchar': + case 'string': + $length = !empty($field['length']) + ? $field['length'] : false; + + $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false; + + return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') + : ($length ? 'VARCHAR('.$length.')' : 'TEXT'); + case 'clob': + if (!empty($field['length'])) { + $length = $field['length']; + if ($length <= 8000) { + return 'VARCHAR('.$length.')'; + } + } + return 'TEXT'; + case 'blob': + if (!empty($field['length'])) { + $length = $field['length']; + if ($length <= 8000) { + return "VARBINARY($length)"; + } } - } - return 'TEXT'; - case 'blob': - if (!empty($field['length'])) { - $length = $field['length']; - if ($length <= 8000) { - return "VARBINARY($length)"; - } - } - return 'IMAGE'; - case 'integer': - return 'INT'; - case 'boolean': - return 'BIT'; - case 'date': - return 'CHAR ('.strlen('YYYY-MM-DD').')'; - case 'time': - return 'CHAR ('.strlen('HH:MM:SS').')'; - case 'timestamp': - return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'; - case 'float': - return 'FLOAT'; - case 'decimal': - $length = !empty($field['length']) ? $field['length'] : 18; - return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; + return 'IMAGE'; + case 'integer': + return 'INT'; + case 'boolean': + return 'BIT'; + case 'date': + return 'CHAR(' . strlen('YYYY-MM-DD') . ')'; + case 'time': + return 'CHAR(' . strlen('HH:MM:SS') . ')'; + case 'timestamp': + return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')'; + case 'float': + return 'FLOAT'; + case 'decimal': + $length = !empty($field['length']) ? $field['length'] : 18; + return 'DECIMAL('.$length.','.$db->options['decimal_places'].')'; } return ''; } @@ -100,10 +107,9 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { * Maps a native array description of a field to a MDB2 datatype and length * * @param array $field native field description - * @author Lukas Smith (PEAR MDB2 library) * @return array containing the various possible types, length, sign, fixed */ - public function mapNativeDatatype($field) { + public function getPortableDeclaration($field) { $db_type = preg_replace('/\d/','', strtolower($field['type']) ); $length = $field['length']; if ((int)$length <= 0) { @@ -154,7 +160,7 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { $length = null; break; default: - throw new Doctrine_DataDict_Mssql_Exception('mapNativeDatatype: unknown database attribute type: '.$db_type); + throw new Doctrine_DataDict_Mssql_Exception('unknown database attribute type: '.$db_type); } return array($type, $length, $unsigned, $fixed);