Oprava počtu řádků při GROUP BY přes více sloupců (Nette Database Table)#1294
Open
radimvaculik wants to merge 2 commits into
Open
Oprava počtu řádků při GROUP BY přes více sloupců (Nette Database Table)#1294radimvaculik wants to merge 2 commits into
radimvaculik wants to merge 2 commits into
Conversation
getCount() nahrazuje neplatné COUNT(DISTINCT sloupec1, sloupec2, ...) počítáním skupin přes poddotaz, takže vrací správný počet i když seskupovací sloupce obsahují NULL hodnoty. Řeší issue #991.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1294 +/- ##
==========================================
+ Coverage 48.77% 48.95% +0.17%
==========================================
Files 61 62 +1
Lines 2901 2905 +4
==========================================
+ Hits 1415 1422 +7
+ Misses 1486 1483 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Metoda Selection::getExplorer() existuje až v nette/database 3.2.9, ale CI běží s 3.2.8. Použití zavedeného reflection helperu getContext() funguje napříč podporovanými verzemi.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NetteDatabaseTableDataSource::getCount()generated invalid SQL for selections grouped by multiple columns. When aGROUP BYwas present it builtCOUNT(DISTINCT col1, col2, ...), which:NULL, so the count is undercounted (returns0when every row has aNULLin one of the grouping columns).wrong number of arguments to function COUNT().Fixes #991.
Fix
Count the number of groups via a subquery instead of relying on
COUNT(DISTINCT ...):This matches the approach already used by
NetteDatabaseDataSource::getCount()and returns the correct count regardless ofNULLvalues in the grouping columns. The duplicatedGROUP BYhandling in both branches of the method was consolidated into a single early check.Tests
Added
testGetCountWithGroupByMultipleColumns()reproducing the issue scenario (grouping by four columns withNULLvalues, 4 rows → 3 groups).getCount()now returns3, consistent withgetData().make qa(PHPStan + phpcs) and the full test suite pass.