-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Oracle platform ignores OFFSET in case if LIMIT is not specified #2509
Conversation
@@ -975,24 +975,30 @@ public function getName() | |||
*/ | |||
protected function doModifyLimitQuery($query, $limit, $offset = null) | |||
{ | |||
$limit = (int) $limit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please remove the integer casting entirely and just rely on the method signature integer|null
for both $limit
and $offset
? Then just check everywhere against null
. Also please remove the $has*
variables as they are unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deeky666 The confusing part here is how is $offset = null
different from $offset = 0
from the SQL semantics standpoint? Should the DBAL produce additional sub-query in the latter case? Right now it doesn't which makes more sense to me.
UPD: comparing $offset
to null
will break unit test:
1) Doctrine\Tests\DBAL\Platforms\OraclePlatformTest::testModifyLimitQuery
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10'
+'SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a WHERE ROWNUM <= 10) WHERE doctrine_rownum >= 1'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morozov yeah good point. But then leave it as before casting both parameters to int
and checking for 0
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deeky666 but unlike OFFSET
, for LIMIT
0
and null
have different meanings — "0 records" and "all records" respectively. There's no complete consistency between existing adapters but all of them except SQL Anywhere only omit $limit
when it's null
. Technically, it is possible to execute a query and retrieve 0 records from it, so the DBAL shouldn't be a limiting factor here. Also from the API consumer standpoint, if there's a bug in the calculation of $limit
on the application end and it's calculated as 0
, I'd better expect 0 records to be returned instead of all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morozov sounds reasonable. Thanks for clearing that up. I'll accept it as is now.
$query = 'SELECT a.' . $column . ' FROM (' . $query . ') a WHERE ROWNUM <= ' . $max; | ||
} | ||
|
||
$query = 'SELECT a.*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use sprintf()
here? Guess that makes it more readable.
0f9d221
to
76d1f93
Compare
@@ -975,24 +975,30 @@ public function getName() | |||
*/ | |||
protected function doModifyLimitQuery($query, $limit, $offset = null) | |||
{ | |||
$limit = (int) $limit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morozov sounds reasonable. Thanks for clearing that up. I'll accept it as is now.
@morozov thank you very much! |
Backported to |
There's a non-empty table
users
. The following script should return all existing record IDs except the 1st one.On Oracle, it returns all records ignoring the value set by calling
setFirstResult()
.