Skip to content

Commit 457a1dc

Browse files
fix: restore backward compatibility for Oracle pagination
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9361461 commit 457a1dc

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎system/Database/OCI8/Builder.php‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,18 @@ protected function _update(string $table, array $values): string
200200
protected function _limit(string $sql, bool $offsetIgnore = false): string
201201
{
202202
$offset = (int) ($offsetIgnore === false ? $this->QBOffset : 0);
203+
if (version_compare($this->db->getVersion(), '12.1', '>=')) {
204+
// OFFSET-FETCH can be used only with the ORDER BY clause
205+
if (empty($this->QBOrderBy)) {
206+
$sql .= ' ORDER BY 1';
207+
}
203208

204-
// OFFSET-FETCH can be used only with the ORDER BY clause
205-
if (! is_array($this->QBOrderBy) || $this->QBOrderBy === []) {
206-
$sql .= ' ORDER BY 1';
209+
return $sql . ' OFFSET ' . $offset . ' ROWS FETCH NEXT ' . $this->QBLimit . ' ROWS ONLY';
207210
}
208211

209-
return $sql . ' OFFSET ' . $offset . ' ROWS FETCH NEXT ' . $this->QBLimit . ' ROWS ONLY';
212+
$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset ? ' WHERE RNUM >= %d' : '');
213+
214+
return sprintf($limitTemplateQuery, $sql, $offset + $this->QBLimit + 1, $offset);
210215
}
211216

212217
/**

0 commit comments

Comments
 (0)