Commit 2c3b8bab authored by zYne's avatar zYne

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

parent 6daa1e34
......@@ -127,6 +127,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* @see Doctrine_Expression
* @see Doctrine_Export
* @see Doctrine_Transaction
* @see Doctrine_Connection::$modules all availible modules
* @param string $name the name of the module to get
* @throws Doctrine_Connection_Exception if trying to get an unknown module
* @return Doctrine_Connection_Module connection module
......
......@@ -24,14 +24,14 @@ Doctrine::autoload('Doctrine_Access');
* Its purpose is to populate object graphs.
*
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
abstract class Doctrine_Hydrate extends Doctrine_Access {
/**
* @var array $fetchmodes an array containing all fetchmodes
......@@ -339,7 +339,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
array_walk($params, array(__CLASS__, 'convertBoolean'));
if( ! $this->view)
$query = $this->getQuery(true);
$query = $this->getQuery($params);
else
$query = $this->view->getSelectSql();
......
......@@ -466,9 +466,11 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
/**
* 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
*/
public function getQuery($executeSubquery = false) {
public function getQuery($params = array()) {
if(empty($this->parts["select"]) || empty($this->parts["from"]))
return false;
......@@ -512,15 +514,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if($needsSubQuery) {
$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':
$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);
break;
case 'pgsql':
// pgsql needs special nested LIMIT subquery
$subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias';
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment