Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions library/Zend/Db/Adapter/Db2.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,25 +680,16 @@ public function limit($sql, $count, $offset = 0)
require_once 'Zend/Db/Adapter/Db2/Exception.php';
throw new Zend_Db_Adapter_Db2_Exception("LIMIT argument offset=$offset is not valid");
}

if ($offset === 0) {
return $sql . " FETCH FIRST $count ROWS ONLY";
}


/**
* DB2 does not implement the LIMIT clause as some RDBMS do.
* We have to simulate it with subqueries and ROWNUM.
* Unfortunately because we use the column wildcard "*",
* this puts an extra column into the query result set.
* DB2Modern versions already have `LIMIT,OFFSET` available.
*/
return "SELECT z2.*
FROM (
SELECT ROW_NUMBER() OVER() AS \"ZEND_DB_ROWNUM\", z1.*
FROM (
" . $sql . "
) z1
) z2
WHERE z2.zend_db_rownum BETWEEN " . ($offset+1) . " AND " . ($offset+$count);
$sql .= " LIMIT $count";
if ($offset > 0) {
$sql .= " OFFSET $offset";
}

return $sql;
}

/**
Expand Down