diff --git a/library/Zend/Db/Adapter/Db2.php b/library/Zend/Db/Adapter/Db2.php index a79e7201e2..c192379fbe 100644 --- a/library/Zend/Db/Adapter/Db2.php +++ b/library/Zend/Db/Adapter/Db2.php @@ -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; } /**