Skip to content

Commit

Permalink
Merge pull request #4984 from morozov/cast-limit-offset-to-int
Browse files Browse the repository at this point in the history
Cast LIMIT and OFFSET to int when building limit query
  • Loading branch information
derrabus committed Nov 11, 2021
2 parents dcbad31 + 9dcfa4c commit 483a518
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Platforms/AbstractPlatform.php
Expand Up @@ -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);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -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<string, mixed> $column
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Platforms/DB2PlatformTest.php
Expand Up @@ -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';
}
}
6 changes: 6 additions & 0 deletions tests/Platforms/OraclePlatformTest.php
Expand Up @@ -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';
}
}

0 comments on commit 483a518

Please sign in to comment.