Commit 442fb477 authored by lsmith's avatar lsmith

- unified getDefaultFieldDeclaration(), force DEFAULT NULL when no default is...

- unified getDefaultFieldDeclaration(), force DEFAULT NULL when no default is set and the field allows nulls
parent 53c044fc
......@@ -230,7 +230,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
}
/**
* 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
......@@ -453,12 +453,9 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
} else {
$default = ' DEFAULT '.$this->conn->quote($field['default']);
}
}
/**
elseif (empty($field['notnull'])) {
} elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
*/
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
......
......@@ -694,6 +694,12 @@ class Doctrine_Export extends Doctrine_Connection_Module
public function getDeclaration($name, array $field)
{
$method = 'get' . $field['type'] . 'Declaration';
if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field);
}
$default = $this->getDefaultFieldDeclaration($field);
$charset = (isset($field['charset']) && $field['charset']) ?
......@@ -710,13 +716,8 @@ class Doctrine_Export extends Doctrine_Connection_Module
$check = (isset($field['check']) && $field['check']) ?
' ' . $field['check'] : '';
$method = 'get' . $field['type'] . 'Declaration';
if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field);
} else {
$dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $unique . $check . $collation;
}
......@@ -730,15 +731,18 @@ class Doctrine_Export extends Doctrine_Connection_Module
*/
public function getDefaultFieldDeclaration($field)
{
$default = '';
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
if (isset($field['default'])) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === '' &&
($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)) {
$field['default'] = null;
if (! empty($field['notnull']) && array_key_exists($field['type'], $this->valid_default_values)) {
$field['default'] = $this->valid_default_values[$field['type']];
}
if ($field['default'] === ''
&& ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
) {
$field['default'] = ' ';
}
}
......
......@@ -512,7 +512,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
*/
public function getDefaultFieldDeclaration($field)
{
$default = '';
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
if ($field['default'] === '') {
$field['default'] = null;
......@@ -530,6 +530,9 @@ class Doctrine_Export_Mysql extends Doctrine_Export
if ($field['type'] == 'enum' && $this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$fieldType = 'varchar';
} else {
if ($field['type'] === 'boolean') {
$fields['default'] = $this->conn->convertBooleans($field['default']);
}
$fieldType = $field['type'];
}
......
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