1
0
mirror of synced 2024-12-13 14:56:01 +03:00

fixes #689, which details problems with the handling of MySQL native enum columns and model class generation.

This commit is contained in:
baron314159 2008-01-23 02:18:36 +00:00
parent aa1592c002
commit e44bdb8e81
3 changed files with 28 additions and 7 deletions

View File

@ -316,23 +316,25 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict
break;
case 'enum':
$type[] = 'enum';
preg_match_all('/\'.+\'/U', $field['type'], $matches);
preg_match_all('/\'((?:\'\'|[^\'])*)\'/', $field['type'], $matches);
$length = 0;
$fixed = false;
if (is_array($matches)) {
foreach ($matches[0] as $value) {
$length = max($length, strlen($value)-2);
foreach ($matches[1] as &$value) {
$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';
if (preg_match('/^(is|has)/', $field['name'])) {
$type = array_reverse($type);
}
} else {
$values = $matches[0];
$values = $matches[1];
}
}
$type[] = 'integer';
break;
case 'set':
$fixed = false;
$type[] = 'text';

View File

@ -45,12 +45,16 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$operator = $e[1];
$value = $e[2];
$conn = $this->query->getConnection();
$alias = $this->query->getTableAlias($reference);
$map = $this->query->getAliasDeclaration($reference);
$table = $map['table'];
// check if value is enumerated 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) == '(') {
// trim brackets
@ -68,7 +72,12 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
$value = array();
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) {
$value[] = $index;
} else {
@ -102,4 +111,4 @@ class Doctrine_Query_JoinCondition extends Doctrine_Query_Condition
return $condition;
}
}
}

View File

@ -88,6 +88,8 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
public function parseValue($value, Doctrine_Table $table = null, $field = null)
{
$conn = $this->query->getConnection();
if (substr($value, 0, 1) == '(') {
// trim brackets
$trimmed = $this->_tokenizer->bracketTrim($value);
@ -112,6 +114,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
foreach ($e as $part) {
if (isset($table) && isset($field)) {
$index = $table->enumIndex($field, trim($part, "'"));
if (false !== $index && $conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) {
$index = $conn->quote($index, 'text');
}
}
if ($index !== false) {
@ -135,6 +141,10 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
if (isset($table) && isset($field)) {
// check if value is enumerated 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) {