Skip to content

Commit

Permalink
Merge pull request #45 from ssnm-a/exclude-union
Browse files Browse the repository at this point in the history
 UNIONが含まれたSQLをcountQuery生成から除外
  • Loading branch information
koriym authored Aug 22, 2019
2 parents 5c5c78d + e0a087d commit 93e31d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Pagerfanta/ExtendedPdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public function getLimitClause($offset, $length)
*/
public function rewriteCountQuery($query)
{
if (\is_int(\strpos(\strtolower($query), 'union'))) {
return '';
}
if (\preg_match('/^\s*SELECT\s+\bDISTINCT\b/is', $query) || \preg_match('/\s+GROUP\s+BY\s+/is', $query)) {
return '';
}
Expand Down
1 change: 1 addition & 0 deletions tests/Pagerfanta/ExtendedPdoAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function splProvider()
['SELECT * FROM posts', [], 'SELECT COUNT(*) FROM posts', 50],
['SELECT DISTINCT id FROM posts', [], '', 50],
['SELECT * FROM posts WHERE id > :num', ['num' => 10], 'SELECT COUNT(*) FROM posts WHERE id > :num', 40],
['SELECT id FROM posts UNION SELECT id FROM posts', [], '', 50],
];
}

Expand Down

0 comments on commit 93e31d2

Please sign in to comment.