1
0
mirror of synced 2025-01-07 09:37:11 +03:00

Fixed limit subquery handling on mysql with prepared statements, fixes #231

This commit is contained in:
zYne 2006-11-16 21:38:59 +00:00
parent 6daa1e3443
commit 2c3b8bab19
3 changed files with 18 additions and 14 deletions

View File

@ -127,6 +127,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @see Doctrine_Expression * @see Doctrine_Expression
* @see Doctrine_Export * @see Doctrine_Export
* @see Doctrine_Transaction * @see Doctrine_Transaction
* @see Doctrine_Connection::$modules all availible modules
* @param string $name the name of the module to get * @param string $name the name of the module to get
* @throws Doctrine_Connection_Exception if trying to get an unknown module * @throws Doctrine_Connection_Exception if trying to get an unknown module
* @return Doctrine_Connection_Module connection module * @return Doctrine_Connection_Module connection module

View File

@ -339,7 +339,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
array_walk($params, array(__CLASS__, 'convertBoolean')); array_walk($params, array(__CLASS__, 'convertBoolean'));
if( ! $this->view) if( ! $this->view)
$query = $this->getQuery(true); $query = $this->getQuery($params);
else else
$query = $this->view->getSelectSql(); $query = $this->view->getSelectSql();

View File

@ -466,9 +466,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
/** /**
* returns the built sql query * returns the built sql query
* *
* @param array $params an array of prepared statement params (needed only in mysql driver
* when limit subquery algorithm is used)
* @return string * @return string
*/ */
public function getQuery($executeSubquery = false) { public function getQuery($params = array()) {
if(empty($this->parts["select"]) || empty($this->parts["from"])) if(empty($this->parts["select"]) || empty($this->parts["from"]))
return false; return false;
@ -512,15 +514,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if($needsSubQuery) { if($needsSubQuery) {
$subquery = $this->getLimitSubquery(); $subquery = $this->getLimitSubquery();
$dbh = $this->connection->getDBH();
// mysql doesn't support LIMIT in subqueries
switch($dbh->getAttribute(PDO::ATTR_DRIVER_NAME)) { switch(strtolower($this->connection->getName())) {
case 'mysql': case 'mysql':
$list = $dbh->query($subquery)->fetchAll(PDO::FETCH_COLUMN); // mysql doesn't support LIMIT in subqueries
$list = $this->conn->execute($subquery, $params)->fetchAll(PDO::FETCH_COLUMN);
$subquery = implode(', ', $list); $subquery = implode(', ', $list);
break; break;
case 'pgsql': case 'pgsql':
// pgsql needs special nested LIMIT subquery
$subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias'; $subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
break; break;
} }