-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: Query Builder limit() problem with OCI8 #9469
Comments
A version would be useful, as our tests already cover this: https://github.com/codeigniter4/CodeIgniter4/blob/develop/tests/system/Database/Live/LimitTest.php#L25 |
Try to run: SELECT BANNER FROM V$VERSION; |
Thank you for that SQL statement: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production |
That is strange. Can you check what you get, when you call: // assuming you use the default connection
$db = db_connect();
echo $db->getVersion();
// and
echo oci_server_version($db->connID); In general, the https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/Database/OCI8/Builder.php#L217-L224 Can you change this method and check if it will work correctly? protected function _limit(string $sql, bool $offsetIgnore = false): string
{
$offset = (int) ($offsetIgnore === false ? $this->QBOffset : 0);
// 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';
} Since we no longer support versions below |
Interesting results:
Results are:
Looking in that
Yet I'm able to immediately do a And yes, if I change the Thank you for your help with this and if there's any more testing I can do for you, please let me know. |
Oh, ok I see it now. The connection is established only right before we execute the query, so obviously there is no I will prepare a fix later. Thank you for the report and feedback. |
PHP Version
8.3
CodeIgniter4 Version
4.6.0
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
Oracle
What happened?
When using Query Builder (OCI8) on an Oracle database, it seems like the
limit()
function is not working properly when returning results for anything after the first page. In other words, if I do alimit(2,0)
, I'll get back the first 2 results correctly, however if I do alimit(2,2)
, instead of getting back the next page of 2 results, instead I get back 3 results and one of the results is a duplicate from the previous page of results.Steps to Reproduce
Using a Model that is for an Oracle table, simply do:
Expected Output
The expected output would be to get back just 2 results when doing
limit(2,2)
, and this can easily be fixed by modifying the Codeigniter4/system/Database/OCI8/Builder.php file and changing this line:$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset !== 0 ? ' WHERE RNUM >= %d' : '');
To this line:
$limitTemplateQuery = 'SELECT * FROM (SELECT INNER_QUERY.*, ROWNUM RNUM FROM (%s) INNER_QUERY WHERE ROWNUM < %d)' . ($offset !== 0 ? ' WHERE RNUM > %d' : '');
Note: All I did was change "RNUM >= %d" to "RNUM > %d".
Anything else?
If you need more details, please let me know. Unfortunately I don't know the specific version of the Oracle server I am accessing, I don't manage the Oracle server itself.
The text was updated successfully, but these errors were encountered: