Commit 0fdb2290 authored by lsmith's avatar lsmith

- added support for Doctrine::ATTR_USE_NATIVE_ENUM (defaults to off, no BC break)

parent 63c8c87a
......@@ -169,6 +169,7 @@ final class Doctrine
const ATTR_DEF_VARCHAR_LENGTH = 114;
const ATTR_DEF_TABLESPACE = 115;
const ATTR_EMULATE_DATABASE = 116;
const ATTR_USE_NATIVE_ENUM = 117;
const ATTR_DEFAULT_SEQUENCE = 133;
/** 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_SET:
case Doctrine::ATTR_EMULATE_DATABASE:
case Doctrine::ATTR_USE_NATIVE_ENUM:
case Doctrine::ATTR_DEFAULT_SEQUENCE:
case Doctrine::ATTR_EXPORT:
case Doctrine::ATTR_DECIMAL_PLACES:
......
......@@ -185,9 +185,17 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
}
}
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 'int':
case 'enum':
if (!empty($field['length'])) {
$length = $field['length'];
if ($length <= 1) {
......
......@@ -1122,10 +1122,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public function enumValue($field, $index)
{
if ($index instanceof Doctrine_Null)
if ($index instanceof Doctrine_Null) {
return $index;
}
if (!$this->conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)
&& isset($this->columns[$field]['values'][$index])
) {
return $this->columns[$field]['values'][$index];
}
return isset($this->columns[$field]['values'][$index]) ? $this->columns[$field]['values'][$index] : $index;
return $index;
}
/**
* enumIndex
......@@ -1138,10 +1145,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
$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;
}
/**
* getColumnCount
return ($index+1);
}
/* getColumnCount
*
* @return integer the number of columns in this table
*/
......
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