added method to properly quote IN (...) strings
Ticket: 383
This commit is contained in:
parent
50b5ecc4a0
commit
4cb332fba4
@ -811,19 +811,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
case 'mysql':
|
case 'mysql':
|
||||||
// mysql doesn't support LIMIT in subqueries
|
// mysql doesn't support LIMIT in subqueries
|
||||||
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
|
$list = $this->_conn->execute($subquery, $params)->fetchAll(Doctrine::FETCH_COLUMN);
|
||||||
$subquery = implode(', ', $list);
|
$subquery = $this->inConditionFromArray($list);
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
// pgsql needs special nested LIMIT subquery
|
// pgsql needs special nested LIMIT subquery
|
||||||
$subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
|
$subquery = ' IN (SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias)';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$field = $this->getTableAlias($rootAlias) . '.' . $table->getIdentifier();
|
$field = $this->getTableAlias($rootAlias) . '.' . $table->getIdentifier();
|
||||||
|
|
||||||
// only append the subquery if it actually contains something
|
// only append the subquery if it actually contains something
|
||||||
if ($subquery !== '') {
|
if ($subquery !== '')
|
||||||
array_unshift($this->parts['where'], $this->_conn->quoteIdentifier($field) . ' IN (' . $subquery . ')');
|
{
|
||||||
|
array_unshift($this->parts['where'], $this->_conn->quoteIdentifier($field) . $subquery);
|
||||||
}
|
}
|
||||||
|
|
||||||
$modifyLimit = false;
|
$modifyLimit = false;
|
||||||
@ -983,7 +984,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subquery = implode(' ', $parts);
|
$subquery = implode(' ', $parts);
|
||||||
|
|
||||||
return $subquery;
|
return $subquery;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1274,6 +1274,40 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
|
|
||||||
return $this->_aliasMap[$componentAlias];
|
return $this->_aliasMap[$componentAlias];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inConditionFromArray
|
||||||
|
*
|
||||||
|
* explode array into quoted array (quick and dirty)
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
*
|
||||||
|
* @return mixed - SQL list of conditions passed, or false if empty
|
||||||
|
*/
|
||||||
|
//TODO: check column type instead of first array value?
|
||||||
|
//TODO: is there cleaner value quoting as part of Doctrine somewhere?
|
||||||
|
public function inConditionFromArray(array $values)
|
||||||
|
{
|
||||||
|
if (empty($values))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$list_values = ' IN (';
|
||||||
|
|
||||||
|
// is first value a string? then assume column is.
|
||||||
|
if (is_string($values[0]))
|
||||||
|
{
|
||||||
|
foreach ($values as &$value)
|
||||||
|
{
|
||||||
|
$value = '\'' . $value . '\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$list_values .= implode(', ', $values);
|
||||||
|
$list_values .= ')';
|
||||||
|
|
||||||
|
return $list_values;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loadRoot
|
* loadRoot
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user