Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: OCI8 limit() method #9472

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
33 changes: 4 additions & 29 deletions system/Database/OCI8/Builder.php
Original file line number Diff line number Diff line change
@@ -48,16 +48,6 @@ class Builder extends BaseBuilder
*/
protected $countString = 'SELECT COUNT(1) ';

/**
* Limit used flag
*
* If we use LIMIT, we'll add a field that will
* throw off num_fields later.
*
* @var bool
*/
protected $limitUsed = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it not exists on parent, this need to be kept, with mark @deprecated for patch release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I realized it never had any use. It was simply a copy-paste from CI3 without the full implementation (in the Result::getFieldCount()), which makes it non-usable. It was a "dead" code from the beginning.

But I'm happy to make changes if more people share your view.


/**
* A reference to the database connection.
*
@@ -214,28 +204,13 @@ protected function _update(string $table, array $values): string
protected function _limit(string $sql, bool $offsetIgnore = false): string
{
$offset = (int) ($offsetIgnore === false ? $this->QBOffset : 0);
if (version_compare($this->db->getVersion(), '12.1', '>=')) {
// OFFSET-FETCH can be used only with the ORDER BY clause
if (empty($this->QBOrderBy)) {
$sql .= ' ORDER BY 1';
}

return $sql . ' OFFSET ' . $offset . ' ROWS FETCH NEXT ' . $this->QBLimit . ' ROWS ONLY';
// OFFSET-FETCH can be used only with the ORDER BY clause
if (empty($this->QBOrderBy)) {
$sql .= ' ORDER BY 1';
}

$this->limitUsed = true;
$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset !== 0 ? ' WHERE RNUM >= %d' : '');

return sprintf($limitTemplateQuery, $sql, $offset + $this->QBLimit + 1, $offset);
}

/**
* Resets the query builder values. Called by the get() function
*/
protected function resetSelect()
{
$this->limitUsed = false;
parent::resetSelect();
return $sql . ' OFFSET ' . $offset . ' ROWS FETCH NEXT ' . $this->QBLimit . ' ROWS ONLY';
}

/**
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/missingType.return.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 201 errors
# total 200 errors

parameters:
ignoreErrors:
@@ -112,11 +112,6 @@ parameters:
count: 1
path: ../../system/Database/MigrationRunner.php

-
message: '#^Method CodeIgniter\\Database\\OCI8\\Builder\:\:resetSelect\(\) has no return type specified\.$#'
count: 1
path: ../../system/Database/OCI8/Builder.php

-
message: '#^Method CodeIgniter\\Database\\Postgre\\Connection\:\:buildDSN\(\) has no return type specified\.$#'
count: 1
Loading
Oops, something went wrong.