- added support for Doctrine::ATTR_USE_NATIVE_ENUM (defaults to off, no BC break)
This commit is contained in:
parent
63c8c87ab7
commit
0fdb229020
@ -169,6 +169,7 @@ final class Doctrine
|
|||||||
const ATTR_DEF_VARCHAR_LENGTH = 114;
|
const ATTR_DEF_VARCHAR_LENGTH = 114;
|
||||||
const ATTR_DEF_TABLESPACE = 115;
|
const ATTR_DEF_TABLESPACE = 115;
|
||||||
const ATTR_EMULATE_DATABASE = 116;
|
const ATTR_EMULATE_DATABASE = 116;
|
||||||
|
const ATTR_USE_NATIVE_ENUM = 117;
|
||||||
const ATTR_DEFAULT_SEQUENCE = 133;
|
const ATTR_DEFAULT_SEQUENCE = 133;
|
||||||
|
|
||||||
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
|
/** TODO: REMOVE THE FOLLOWING CONSTANTS AND UPDATE THE DOCS ! */
|
||||||
|
@ -125,6 +125,7 @@ abstract class Doctrine_Configurable extends Doctrine_Object
|
|||||||
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
|
case Doctrine::ATTR_ACCESSOR_PREFIX_GET:
|
||||||
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
|
case Doctrine::ATTR_ACCESSOR_PREFIX_SET:
|
||||||
case Doctrine::ATTR_EMULATE_DATABASE:
|
case Doctrine::ATTR_EMULATE_DATABASE:
|
||||||
|
case Doctrine::ATTR_USE_NATIVE_ENUM:
|
||||||
case Doctrine::ATTR_DEFAULT_SEQUENCE:
|
case Doctrine::ATTR_DEFAULT_SEQUENCE:
|
||||||
case Doctrine::ATTR_EXPORT:
|
case Doctrine::ATTR_EXPORT:
|
||||||
case Doctrine::ATTR_DECIMAL_PLACES:
|
case Doctrine::ATTR_DECIMAL_PLACES:
|
||||||
|
@ -185,9 +185,17 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'LONGBLOB';
|
return 'LONGBLOB';
|
||||||
|
case 'enum':
|
||||||
|
if ($this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
||||||
|
$values = array();
|
||||||
|
foreach ($field['values'] as $value) {
|
||||||
|
$values[] = $this->conn->quote($value, 'varchar');
|
||||||
|
}
|
||||||
|
return 'ENUM('.implode(', ', $values).')';
|
||||||
|
}
|
||||||
|
// fall back to integer
|
||||||
case 'integer':
|
case 'integer':
|
||||||
case 'int':
|
case 'int':
|
||||||
case 'enum':
|
|
||||||
if (!empty($field['length'])) {
|
if (!empty($field['length'])) {
|
||||||
$length = $field['length'];
|
$length = $field['length'];
|
||||||
if ($length <= 1) {
|
if ($length <= 1) {
|
||||||
|
@ -1122,10 +1122,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function enumValue($field, $index)
|
public function enumValue($field, $index)
|
||||||
{
|
{
|
||||||
if ($index instanceof Doctrine_Null)
|
if ($index instanceof Doctrine_Null) {
|
||||||
return $index;
|
return $index;
|
||||||
|
}
|
||||||
|
|
||||||
return isset($this->columns[$field]['values'][$index]) ? $this->columns[$field]['values'][$index] : $index;
|
if (!$this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)
|
||||||
|
&& isset($this->columns[$field]['values'][$index])
|
||||||
|
) {
|
||||||
|
return $this->columns[$field]['values'][$index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $index;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* enumIndex
|
* enumIndex
|
||||||
@ -1138,10 +1145,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
{
|
{
|
||||||
$values = $this->getEnumValues($field);
|
$values = $this->getEnumValues($field);
|
||||||
|
|
||||||
return array_search($value, $values);
|
$index = array_search($value, $values);
|
||||||
|
if ($index === false || !$this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
|
||||||
|
return $index;
|
||||||
}
|
}
|
||||||
/**
|
return ($index+1);
|
||||||
* getColumnCount
|
}
|
||||||
|
/* getColumnCount
|
||||||
*
|
*
|
||||||
* @return integer the number of columns in this table
|
* @return integer the number of columns in this table
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user