Count SQL generation fails on DISTINCT in subquery
6 views
Skip to first unread message
Sergejs Gribs
unread,
Nov 30, 2010, 3:07:52 AM11/30/10
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to in-port...@googlegroups.com
There's bug with 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.
I attached patch that fixes it. Also, it now checks for ANY whitespaces between SELECT and DISTINCT instead of one space.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to in-port...@googlegroups.com
Thanks for noticing that. Now we will know, that if pagination is incorrect and there is a DISTINCT somewhere, then this patch should fix that.
On Tue, Nov 30, 2010 at 10:07 AM, Sergejs Gribs <serg...@gmail.com> wrote:
There's bug with 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.
I attached patch that fixes it. Also, it now checks for ANY whitespaces between SELECT and DISTINCT instead of one space.