- unified getDefaultFieldDeclaration(), force DEFAULT NULL when no default is set and the field allows nulls
This commit is contained in:
parent
53c044fc4d
commit
442fb47768
@ -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
|
* @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
|
||||||
@ -440,25 +440,22 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
|
|||||||
* declare the specified field.
|
* declare the specified field.
|
||||||
*/
|
*/
|
||||||
public function getIntegerDeclaration($name, $field)
|
public function getIntegerDeclaration($name, $field)
|
||||||
{
|
{
|
||||||
$default = $autoinc = '';
|
$default = $autoinc = '';
|
||||||
if ( ! empty($field['autoincrement'])) {
|
if ( ! empty($field['autoincrement'])) {
|
||||||
$autoinc = ' AUTO_INCREMENT';
|
$autoinc = ' AUTO_INCREMENT';
|
||||||
} elseif (array_key_exists('default', $field)) {
|
} elseif (array_key_exists('default', $field)) {
|
||||||
if ($field['default'] === '') {
|
if ($field['default'] === '') {
|
||||||
$field['default'] = empty($field['notnull']) ? null : 0;
|
$field['default'] = empty($field['notnull']) ? null : 0;
|
||||||
}
|
}
|
||||||
if (is_null($field['default'])) {
|
if (is_null($field['default'])) {
|
||||||
$default = ' DEFAULT NULL';
|
$default = ' DEFAULT NULL';
|
||||||
} else {
|
} else {
|
||||||
$default = ' DEFAULT '.$this->conn->quote($field['default']);
|
$default = ' DEFAULT '.$this->conn->quote($field['default']);
|
||||||
}
|
}
|
||||||
}
|
} elseif (empty($field['notnull'])) {
|
||||||
/**
|
|
||||||
elseif (empty($field['notnull'])) {
|
|
||||||
$default = ' DEFAULT NULL';
|
$default = ' DEFAULT NULL';
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
$notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
|
||||||
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
|
$unsigned = (isset($field['unsigned']) && $field['unsigned']) ? ' UNSIGNED' : '';
|
||||||
@ -467,4 +464,4 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
|
|||||||
|
|
||||||
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
|
return $name . ' ' . $this->getNativeDeclaration($field) . $unsigned . $default . $notnull . $autoinc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -694,6 +694,12 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
|||||||
public function getDeclaration($name, array $field)
|
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);
|
$default = $this->getDefaultFieldDeclaration($field);
|
||||||
|
|
||||||
$charset = (isset($field['charset']) && $field['charset']) ?
|
$charset = (isset($field['charset']) && $field['charset']) ?
|
||||||
@ -710,13 +716,8 @@ class Doctrine_Export extends Doctrine_Connection_Module
|
|||||||
$check = (isset($field['check']) && $field['check']) ?
|
$check = (isset($field['check']) && $field['check']) ?
|
||||||
' ' . $field['check'] : '';
|
' ' . $field['check'] : '';
|
||||||
|
|
||||||
$method = 'get' . $field['type'] . 'Declaration';
|
$dec = $this->conn->dataDict->getNativeDeclaration($field);
|
||||||
|
|
||||||
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;
|
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)
|
public function getDefaultFieldDeclaration($field)
|
||||||
{
|
{
|
||||||
$default = '';
|
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
|
||||||
if (isset($field['default'])) {
|
if (isset($field['default'])) {
|
||||||
if ($field['default'] === '') {
|
if ($field['default'] === '') {
|
||||||
$field['default'] = empty($field['notnull'])
|
$field['default'] = null;
|
||||||
? null : $this->valid_default_values[$field['type']];
|
if (! empty($field['notnull']) && array_key_exists($field['type'], $this->valid_default_values)) {
|
||||||
|
$field['default'] = $this->valid_default_values[$field['type']];
|
||||||
|
}
|
||||||
|
|
||||||
if ($field['default'] === '' &&
|
if ($field['default'] === ''
|
||||||
($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)) {
|
&& ($this->conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)
|
||||||
$field['default'] = null;
|
) {
|
||||||
|
$field['default'] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export
|
|||||||
*/
|
*/
|
||||||
public function getDefaultFieldDeclaration($field)
|
public function getDefaultFieldDeclaration($field)
|
||||||
{
|
{
|
||||||
$default = '';
|
$default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
|
||||||
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
|
if (isset($field['default']) && ( ! isset($field['length']) || $field['length'] <= 255)) {
|
||||||
if ($field['default'] === '') {
|
if ($field['default'] === '') {
|
||||||
$field['default'] = null;
|
$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)) {
|
if ($field['type'] == 'enum' && $this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
||||||
$fieldType = 'varchar';
|
$fieldType = 'varchar';
|
||||||
} else {
|
} else {
|
||||||
|
if ($field['type'] === 'boolean') {
|
||||||
|
$fields['default'] = $this->conn->convertBooleans($field['default']);
|
||||||
|
}
|
||||||
$fieldType = $field['type'];
|
$fieldType = $field['type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user