Commit e44bdb8e authored by baron314159's avatar baron314159

fixes #689, which details problems with the handling of MySQL native enum...

fixes #689, which details problems with the handling of MySQL native enum columns and model class generation.
parent aa1592c0
...@@ -316,23 +316,25 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict ...@@ -316,23 +316,25 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
break; break;
case 'enum': case 'enum':
$type[] = 'enum'; $type[] = 'enum';
preg_match_all('/\'.+\'/U', $field['type'], $matches); preg_match_all('/\'((?:\'\'|[^\'])*)\'/', $field['type'], $matches);
$length = 0; $length = 0;
$fixed = false; $fixed = false;
if (is_array($matches)) { if (is_array($matches)) {
foreach ($matches[0] as $value) { foreach ($matches[1] as &$value) {
$length = max($length, strlen($value)-2); $value = str_replace('\'\'', '\'', $value);
$length = max($length, strlen($value));
} }
if ($length == '1' && count($matches[0]) == 2) { if ($length == '1' && count($matches[1]) == 2) {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} else { } else {
$values = $matches[0]; $values = $matches[1];
} }
} }
$type[] = 'integer'; $type[] = 'integer';
break;
case 'set': case 'set':
$fixed = false; $fixed = false;
$type[] = 'text'; $type[] = 'text';
......
...@@ -45,12 +45,16 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition ...@@ -45,12 +45,16 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$operator = $e[1]; $operator = $e[1];
$value = $e[2]; $value = $e[2];
$conn = $this->query->getConnection();
$alias = $this->query->getTableAlias($reference); $alias = $this->query->getTableAlias($reference);
$map = $this->query->getAliasDeclaration($reference); $map = $this->query->getAliasDeclaration($reference);
$table = $map['table']; $table = $map['table'];
// check if value is enumerated value // check if value is enumerated value
$enumIndex = $table->enumIndex($field, trim($value, "'")); $enumIndex = $table->enumIndex($field, trim($value, "'"));
if (false !== $enumIndex && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$enumIndex = $conn->quote($enumIndex, 'text');
}
if (substr($value, 0, 1) == '(') { if (substr($value, 0, 1) == '(') {
// trim brackets // trim brackets
...@@ -68,7 +72,12 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition ...@@ -68,7 +72,12 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$value = array(); $value = array();
foreach ($e as $part) { foreach ($e as $part) {
$index = $table->enumIndex($field, trim($part, "'")); $index = $table->enumIndex($field, trim($part, "'"));
if (false !== $index && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$index = $conn->quote($index, 'text');
}
if ($index !== false) { if ($index !== false) {
$value[] = $index; $value[] = $index;
} else { } else {
...@@ -102,4 +111,4 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition ...@@ -102,4 +111,4 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
return $condition; return $condition;
} }
} }
\ No newline at end of file
...@@ -88,6 +88,8 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition ...@@ -88,6 +88,8 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
public function parseValue($value, Doctrine_Table $table = null, $field = null) public function parseValue($value, Doctrine_Table $table = null, $field = null)
{ {
$conn = $this->query->getConnection();
if (substr($value, 0, 1) == '(') { if (substr($value, 0, 1) == '(') {
// trim brackets // trim brackets
$trimmed = $this->_tokenizer->bracketTrim($value); $trimmed = $this->_tokenizer->bracketTrim($value);
...@@ -112,6 +114,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition ...@@ -112,6 +114,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
foreach ($e as $part) { foreach ($e as $part) {
if (isset($table) && isset($field)) { if (isset($table) && isset($field)) {
$index = $table->enumIndex($field, trim($part, "'")); $index = $table->enumIndex($field, trim($part, "'"));
if (false !== $index && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$index = $conn->quote($index, 'text');
}
} }
if ($index !== false) { if ($index !== false) {
...@@ -135,6 +141,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition ...@@ -135,6 +141,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
if (isset($table) && isset($field)) { if (isset($table) && isset($field)) {
// check if value is enumerated value // check if value is enumerated value
$enumIndex = $table->enumIndex($field, trim($value, "'")); $enumIndex = $table->enumIndex($field, trim($value, "'"));
if (false !== $enumIndex && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$enumIndex = $conn->quote($enumIndex, 'text');
}
} }
if ($enumIndex !== false) { if ($enumIndex !== false) {
......
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