Commit 9df8e4d0 authored by zYne's avatar zYne

small fixes for datadict drivers

parent b8257aad
...@@ -53,12 +53,19 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module { ...@@ -53,12 +53,19 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module {
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getTypeDeclaration($field) { public function getNativeDeclaration($field) {
switch ($field['type']) { switch($field['type']) {
case 'varchar':
case 'string':
case 'array':
case 'object':
case 'char':
case 'text': case 'text':
$length = !empty($field['length']) $length = !empty($field['length'])
? $field['length'] : $db->options['default_text_field_length']; ? $field['length'] : 16777215; // TODO: $db->options['default_text_field_length'];
$fixed = !empty($field['fixed']) ? $field['fixed'] : false;
$fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')'; return $fixed ? 'CHAR('.$length.')' : 'VARCHAR('.$length.')';
case 'clob': case 'clob':
return 'BLOB SUB_TYPE 1'; return 'BLOB SUB_TYPE 1';
...@@ -83,12 +90,12 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module { ...@@ -83,12 +90,12 @@ class Doctrine_DataDict_Firebird extends Doctrine_Connection_Module {
return ''; 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 * @param array $field native field description
* @return array containing the various possible types, length, sign, fixed * @return array containing the various possible types, length, sign, fixed
*/ */
public function mapNativeDatatype($field) { public function getPortableDeclaration($field) {
$length = $field['length']; $length = $field['length'];
if((int) $length <= 0) if((int) $length <= 0)
......
...@@ -50,49 +50,56 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { ...@@ -50,49 +50,56 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module {
* notnull * notnull
* Boolean flag that indicates whether this field is constrained * Boolean flag that indicates whether this field is constrained
* to not be set to null. * to not be set to null.
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library) *
* @return string DBMS specific SQL code portion that should be used to * @return string DBMS specific SQL code portion that should be used to
* declare the specified field. * declare the specified field.
*/ */
public function getTypeDeclaration($field) { public function getNativeDeclaration($field) {
switch ($field['type']) { switch ($field['type']) {
case 'text': case 'array':
$length = !empty($field['length']) case 'object':
? $field['length'] : false; case 'text':
$fixed = !empty($field['fixed']) ? $field['fixed'] : false; case 'char':
return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')') case 'varchar':
: ($length ? 'VARCHAR('.$length.')' : 'TEXT'); case 'string':
case 'clob': $length = !empty($field['length'])
if (!empty($field['length'])) { ? $field['length'] : false;
$length = $field['length'];
if ($length <= 8000) { $fixed = ((isset($field['fixed']) && $field['fixed']) || $field['type'] == 'char') ? true : false;
return 'VARCHAR('.$length.')';
} return $fixed ? ($length ? 'CHAR('.$length.')' : 'CHAR('.$db->options['default_text_field_length'].')')
} : ($length ? 'VARCHAR('.$length.')' : 'TEXT');
return 'TEXT'; case 'clob':
case 'blob': if (!empty($field['length'])) {
if (!empty($field['length'])) { $length = $field['length'];
$length = $field['length']; if ($length <= 8000) {
if ($length <= 8000) { return 'VARCHAR('.$length.')';
return "VARBINARY($length)"; }
}
return 'TEXT';
case 'blob':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 8000) {
return "VARBINARY($length)";
}
} }
} return 'IMAGE';
return 'IMAGE'; case 'integer':
case 'integer': return 'INT';
return 'INT'; case 'boolean':
case 'boolean': return 'BIT';
return 'BIT'; case 'date':
case 'date': return 'CHAR(' . strlen('YYYY-MM-DD') . ')';
return 'CHAR ('.strlen('YYYY-MM-DD').')'; case 'time':
case 'time': return 'CHAR(' . strlen('HH:MM:SS') . ')';
return 'CHAR ('.strlen('HH:MM:SS').')'; case 'timestamp':
case 'timestamp': return 'CHAR(' . strlen('YYYY-MM-DD HH:MM:SS') . ')';
return 'CHAR ('.strlen('YYYY-MM-DD HH:MM:SS').')'; case 'float':
case 'float': return 'FLOAT';
return 'FLOAT'; case 'decimal':
case 'decimal': $length = !empty($field['length']) ? $field['length'] : 18;
$length = !empty($field['length']) ? $field['length'] : 18; return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
return 'DECIMAL('.$length.','.$db->options['decimal_places'].')';
} }
return ''; return '';
} }
...@@ -100,10 +107,9 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { ...@@ -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 * Maps a native array description of a field to a MDB2 datatype and length
* *
* @param array $field native field description * @param array $field native field description
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @return array containing the various possible types, length, sign, fixed * @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']) ); $db_type = preg_replace('/\d/','', strtolower($field['type']) );
$length = $field['length']; $length = $field['length'];
if ((int)$length <= 0) { if ((int)$length <= 0) {
...@@ -154,7 +160,7 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module { ...@@ -154,7 +160,7 @@ class Doctrine_DataDict_Mssql extends Doctrine_Connection_Module {
$length = null; $length = null;
break; break;
default: 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); return array($type, $length, $unsigned, $fixed);
......
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