#107 Wrong row count on DISTINCT queries

closed-rejected
nobody
None
5
2002-06-21
2002-06-13
Anonymous
No

When running a DISTINCT query such as 'SELECT
DISTINCT id FROM table' the wrong row count is
reported because the distinct is not taken into account
when running the separate query to calculate row count.

We fixed this by using a regular expression check to
detemine if a distinct query was run. If so, we then run
a separate count query and report that row count.
These changes were made in the IF statement starting
on row 295 of sql.php.

New code:
if (!empty($array[1])) {
// ... and makes a count(*) to count the entries
if(eregi("distinct (.*) from ", $sql_query, $reg))
$count_query = 'SELECT COUNT(distinct '.$reg[1].')
AS count FROM ' . $array[1];
else
$count_query = 'SELECT COUNT(*) AS count
FROM ' . $array[1];
$OPresult = mysql_query($count_query);
if ($OPresult) {
$unlim_num_rows = mysql_result($OPresult,
0, 'count');
}
mysql_free_result($OPresult);
} else {

Discussion

  • Svetlozar Kovachev

    Logged In: YES
    user_id=553406

    Look at patch #565627

     
  • Marc Delisle

    Marc Delisle - 2002-06-21

    Logged In: YES
    user_id=210714

    We got another patch for this. thanks anyway.

     
  • Marc Delisle

    Marc Delisle - 2002-06-21
    • status: open --> closed-rejected