We have moved to Github. Please open tickets there.

Opened 5 years ago

Closed 5 years ago

#379 closed Defect (fixed)

get_entities_from_metadata: count returns wrong number of records

Reported by: pillgrim Owned by:
Priority: critical Milestone: Elgg 1.1
Component: Core Version: 1.0
Severity: critical Keywords: sql, count
Cc: brettp Difficulty:

Description

In both get_entities_from_metadata and get_entities_from_metadata_multi, count() returns wrong number of entities. I've found the problem and a solution at http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html, here is a solution for Elgg:

Index: engine/lib/metadata.php
===================================================================
--- engine/lib/metadata.php     (revision 57)
+++ engine/lib/metadata.php     (working copy)
@@ -517,7 +517,7 @@
                if (!$count) {
                        $query = "SELECT distinct e.* ";
                } else {
-                       $query = "SELECT count(e.guid) as total ";
+                       $query = "SELECT count(distinct e.guid) as total ";
                }

                $query .= "from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid where";
@@ -622,7 +622,7 @@
                        $where[] = "e.container_guid = {$owner_guid}";

                if ($count) {
-                       $query = "SELECT count(e.guid) as total ";
+                       $query = "SELECT count(distinct e.guid) as total ";
                } else {
                        $query = "SELECT distinct e.* ";
                }

Change History (1)

comment:1 Changed 5 years ago by marcus

  • Resolution set to fixed
  • Status changed from new to closed

(In [svn:2159]) Closes #379

Note: See TracTickets for help on using tickets.