diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index e7f0819b585..f22fab5bc19 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -3365,7 +3365,11 @@ final public function modifyLimitQuery($query, $limit, $offset = 0) )); } - return $this->doModifyLimitQuery($query, $limit, $offset); + if ($limit !== null) { + $limit = (int) $limit; + } + + return $this->doModifyLimitQuery($query, $limit, (int) $offset); } /** diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index b5cfa25b1cf..1d648ec6a92 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -1470,6 +1470,19 @@ public function testZeroOffsetWithoutLimitIsIgnored(): void ); } + public function testLimitOffsetCastToInt(): void + { + self::assertSame( + $this->getLimitOffsetCastToIntExpectedQuery(), + $this->platform->modifyLimitQuery('SELECT * FROM user', '1 BANANA', '2 APPLES') + ); + } + + protected function getLimitOffsetCastToIntExpectedQuery(): string + { + return 'SELECT * FROM user LIMIT 1 OFFSET 2'; + } + /** * @param array $column * diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index fe07ca6f6b3..c8d0f25606c 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -773,4 +773,10 @@ public function testQuotesTableNameInListTableForeignKeysSQL(): void $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") ); } + + protected function getLimitOffsetCastToIntExpectedQuery(): string + { + return 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM' + . ' FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 3 AND db22.DC_ROWNUM <= 3'; + } } diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 88a88147bff..e0f1e6d1663 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -986,4 +986,10 @@ public function asciiStringSqlDeclarationDataProvider(): array ['CHAR(12)', ['length' => 12, 'fixed' => true]], ]; } + + protected function getLimitOffsetCastToIntExpectedQuery(): string + { + return 'SELECT * FROM (SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a WHERE ROWNUM <= 3)' + . ' WHERE doctrine_rownum >= 3'; + } }