In-Portal Issue Tracker - In-Portal CMS
Viewing Issue Advanced Details
938 [In-Portal CMS] Database bug report always 2010-11-30 12:10 2011-03-30 09:53
BaSSiST  
alex  
normal  
closed 5.1.1  
fixed  
 
none 5.1.2-B1  
http://groups.google.com/group/in-portal-bugs/browse_thread/thread/4635504373ca3d86
Fixes Count SQLs with DISTINCT in sub-query
0
0000938: Generation of COUNT SQL Fails with DISTINCT in sub-query
There is a bug in kDBList::getCountSQL method, which generates SQL for counting list totals.

It checks if there's DISTINCT in SQL and, if it's there, tries to replace it for COUNT(DISTINCT...) construction instead of simple COUNT(*).

Problem is that it checks for distinct in ANY place of query, but replaces it in beginning, so, if there's DISTINCT in subquery, it won't replace anything. So, count SQL will be equal to list SQL, and you will get first record's first field's value (according to kDBConnection::GetOne logic) as record count.
Patch also, checks for ANY number of whitespaces between SELECT and DISTINCT, instead of one space.
patch count+sql+with+distinct.patch (622) 2010-11-30 12:10
http://tracker.in-portal.org/file_download.php?file_id=862&type=bug
Issue History
2011-03-30 09:53 Dmitry Note Added: 0003358
2011-03-30 09:53 Dmitry Status resolved => closed
2011-01-05 06:05 alex Note Added: 0003161
2011-01-05 06:05 alex Status reviewed and tested => resolved
2011-01-05 06:05 alex Fixed in Version => 5.1.2-B1
2011-01-05 06:05 alex Resolution open => fixed
2011-01-05 06:05 alex Assigned To !COMMUNITY => alex
2011-01-05 06:05 alex Changeset attached 5.1.x r14119
2011-01-05 06:05 alex Note Added: 0003160
2011-01-05 06:05 alex Status needs testing => reviewed and tested
2010-11-30 14:01 alex Developer Dmitry => BaSSiST
2010-11-30 12:11 Dmitry Assigned To => !COMMUNITY
2010-11-30 12:11 Dmitry Developer BaSSiST => Dmitry
2010-11-30 12:11 Dmitry Status active => needs testing
2010-11-30 12:11 Dmitry Reporter Dmitry => BaSSiST
2010-11-30 12:11 Dmitry Developer => BaSSiST
2010-11-30 12:10 Dmitry New Issue
2010-11-30 12:10 Dmitry File Added: count+sql+with+distinct.patch
2010-11-30 12:10 Dmitry Reference => http://groups.google.com/group/in-portal-bugs/browse_thread/thread/4635504373ca3d86
2010-11-30 12:10 Dmitry Change Log Message => Fixes Count SQLs with DISTINCT in sub-query

Notes
(0003160)
alex   
2011-01-05 06:05   
ok
(0003161)
alex   
2011-01-05 06:05   
Fix committed to 5.1.x branch. Commit Message:

Fixes 0000938: Generation of COUNT SQL Fails with DISTINCT in sub-query
Commit on behalf of Sergey
(0003358)
Dmitry   
2011-03-30 09:53   
Closing, since 5.1.2 release has been released.