From 0aac52ef74bb4c0464c09300c377107d8404fa15 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 4 Jan 2007 23:52:18 +0000 Subject: [PATCH] --- lib/Doctrine/Export.php | 12 +++++++----- lib/Doctrine/Hook.php | 29 ++++++++++++++++++++++------ lib/Doctrine/Hook/Parser/Complex.php | 14 ++++---------- lib/Doctrine/Hook/WordLike.php | 18 ++++++++++++----- lib/Doctrine/Query.php | 2 -- 5 files changed, 47 insertions(+), 28 deletions(-) diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 38d5e9e1f..160965e83 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -133,10 +133,12 @@ class Doctrine_Export extends Doctrine_Connection_Module * * @return void */ - public function createTable($name, array $fields, array $options = array()) { - if ( ! $name) + public function createTable($name, array $fields, array $options = array()) + { + if ( ! $name) { throw new Doctrine_Export_Exception('no valid table name specified'); - + } + if (empty($fields)) { throw new Doctrine_Export_Exception('no fields specified for table '.$name); } @@ -148,7 +150,7 @@ class Doctrine_Export extends Doctrine_Connection_Module $name = $this->conn->quoteIdentifier($name, true); $query = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')'; - + print $query."
"; return $this->conn->exec($query); } /** @@ -653,7 +655,7 @@ class Doctrine_Export extends Doctrine_Connection_Module $this->createTable($table->getTableName(), $columns); } catch(Doctrine_Connection_Exception $e) { - $reporter->add(E_ERROR, $e->getCode()); + $reporter->add(E_ERROR, $e->getMessage()); } return $reporter; diff --git a/lib/Doctrine/Hook.php b/lib/Doctrine/Hook.php index e25e2f83b..208fc408d 100644 --- a/lib/Doctrine/Hook.php +++ b/lib/Doctrine/Hook.php @@ -54,17 +54,22 @@ class Doctrine_Hook */ protected $params = array(); /** - * @var array $fieldParsers + * @var array $fieldParsers custom field parsers array + * keys as field names in the format componentAlias.FieldName + * values as parser names / objects */ protected $fieldParsers = array(); /** - * @var array $typeParsers + * @var array $typeParsers type parsers array + * keys as type names and values as parser names / objects */ protected $typeParsers = array( 'char' => 'Doctrine_Hook_WordLike', 'string' => 'Doctrine_Hook_WordLike', 'integer' => 'Doctrine_Hook_Integer', + 'time' => 'Doctrine_Hook_Time', + 'date' => 'Doctrine_Hook_Date', ); /** @@ -88,13 +93,25 @@ class Doctrine_Hook { return $this->query; } - public function leftJoin($dql) + /** + * setTypeParser + * + * @param string $type type name + * @param string|object $parser parser name or custom parser object + */ + public function setTypeParser($type, $parser) { - + $this->typeParsers[$type] = $parser; } - public function innerJoin($dql) + /** + * setFieldParser + * + * @param string $field field name + * @param string|object $parser parser name or custom parser object + */ + public function setFieldParser($field, $parser) { - + $this->fieldParsers[$field] = $parser; } /** * hookWhere diff --git a/lib/Doctrine/Hook/Parser/Complex.php b/lib/Doctrine/Hook/Parser/Complex.php index b0d8ea6b8..239148498 100644 --- a/lib/Doctrine/Hook/Parser/Complex.php +++ b/lib/Doctrine/Hook/Parser/Complex.php @@ -58,33 +58,27 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser */ public function parseClause($alias, $field, $value) { - $parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')'); + $parts = Doctrine_Query::quoteExplode($value, ' AND '); if (count($parts) > 1) { $ret = array(); foreach ($parts as $part) { - $part = Doctrine_Query::bracketTrim($part, '(', ')'); $ret[] = $this->parseSingle($alias, $field, $part); } $r = implode(' AND ', $ret); } else { - $parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')'); + $parts = Doctrine_Query::quoteExplode($value, ' OR '); if (count($parts) > 1) { $ret = array(); foreach ($parts as $part) { - $part = Doctrine_Query::bracketTrim($part, '(', ')'); $ret[] = $this->parseClause($alias, $field, $part); } $r = implode(' OR ', $ret); } else { - if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') { - return $this->parseClause(substr($parts[0],1,-1)); - } else { - $ret = $this->parseSingle($alias, $field, $parts[0]); - return $ret; - } + $ret = $this->parseSingle($alias, $field, $parts[0]); + return $ret; } } return '(' . $r . ')'; diff --git a/lib/Doctrine/Hook/WordLike.php b/lib/Doctrine/Hook/WordLike.php index 088a3eacf..4446d0ebc 100644 --- a/lib/Doctrine/Hook/WordLike.php +++ b/lib/Doctrine/Hook/WordLike.php @@ -46,12 +46,20 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex */ public function parseSingle($alias, $field, $value) { - $e2 = explode(' ',$value); + if (strpos($value, "'") !== false) { + $value = Doctrine_Query::bracketTrim($value, "'", "'"); + + $a[] = $alias . '.' . $field . ' LIKE ?'; + $this->params[] = $value . '%'; - foreach ($e2 as $v) { - $v = trim($v); - $a[] = $alias. '.' . $field . ' LIKE ?'; - $this->params[] = $v . '%'; + } else { + $e2 = explode(' ',$value); + + foreach ($e2 as $v) { + $v = trim($v); + $a[] = $alias . '.' . $field . ' LIKE ?'; + $this->params[] = $v . '%'; + } } return implode(' OR ', $a); } diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index badc5409f..97ef426fc 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1023,8 +1023,6 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { * parameters: * $str = email LIKE 'John@example.com' * $d = ' AND ' - * $e1 = '(' - * $e2 = ')' * * would return an array: * array("email", "LIKE", "'John@example.com'")