From e44bdb8e81d8819abe34e772a18d11b1e620c765 Mon Sep 17 00:00:00 2001 From: baron314159 Date: Wed, 23 Jan 2008 02:18:36 +0000 Subject: [PATCH] fixes #689, which details problems with the handling of MySQL native enum columns and model class generation. --- lib/Doctrine/DataDict/Mysql.php | 12 +++++++----- lib/Doctrine/Query/JoinCondition.php | 13 +++++++++++-- lib/Doctrine/Query/Where.php | 10 ++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DataDict/Mysql.php b/lib/Doctrine/DataDict/Mysql.php index 3d63c8ec0..9567c8072 100644 --- a/lib/Doctrine/DataDict/Mysql.php +++ b/lib/Doctrine/DataDict/Mysql.php @@ -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'; diff --git a/lib/Doctrine/Query/JoinCondition.php b/lib/Doctrine/Query/JoinCondition.php index 9ef0b87f6..598a84e35 100644 --- a/lib/Doctrine/Query/JoinCondition.php +++ b/lib/Doctrine/Query/JoinCondition.php @@ -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; } -} \ No newline at end of file +} diff --git a/lib/Doctrine/Query/Where.php b/lib/Doctrine/Query/Where.php index dddae72c2..7ecd87162 100644 --- a/lib/Doctrine/Query/Where.php +++ b/lib/Doctrine/Query/Where.php @@ -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) {