1
0
mirror of synced 2025-01-06 00:57:10 +03:00

Fixed pgsql limit subquery algorithm

This commit is contained in:
zYne 2006-11-01 17:08:35 +00:00
parent 6b4e032857
commit b75ef330d4

View File

@ -530,17 +530,23 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
* @return string the limit subquery * @return string the limit subquery
*/ */
public function getLimitSubquery() { public function getLimitSubquery() {
$k = array_keys($this->tables); $k = array_keys($this->tables);
$table = $this->tables[$k[0]]; $table = $this->tables[$k[0]];
$primaryKey = $table->getTableName() . '.' . $table->getIdentifier();
// initialize the base of the subquery
$subquery = 'SELECT DISTINCT ' . $primaryKey;
$subquery = 'SELECT DISTINCT ' . $table->getTableName()
. '.' . $table->getIdentifier();
if($this->connection->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') { if($this->connection->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') {
// pgsql needs the order by fields to be preserved in select clause
foreach($this->parts['orderby'] as $part) { foreach($this->parts['orderby'] as $part) {
$e = explode(' ', $part); $e = explode(' ', $part);
$subquery .= ', ' . $e[0]; // don't add primarykey column (its already in the select clause)
if($e[0] !== $primaryKey)
$subquery .= ', ' . $e[0];
} }
} }