This commit is contained in:
parent
83d89b766d
commit
0aac52ef74
5 changed files with 47 additions and 28 deletions
|
@ -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."<br \>";
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 . ')';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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'")
|
||||
|
|
Loading…
Add table
Reference in a new issue