1
0
mirror of synced 2025-01-17 22:11:41 +03:00

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

This commit is contained in:
lsmith 2007-09-02 08:53:16 +00:00
parent 63c8c87ab7
commit 0fdb229020
4 changed files with 96 additions and 76 deletions

View File

@ -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 ! */

View File

@ -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:

View File

@ -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) {

View File

@ -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;
}
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
@ -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
*/