On Apr 29, 2020, at 2:21 PM, Paul Dennis via 4D_Tech <4d_tech@lists.4d.com> 
wrote:
> 
> I have a collection created from arrays via mysql. This contains duplicated
> elements. I'm trying to do the equivalent of distinct values but the
> collection.distinct command does not do the distinction on a single
> attribute. 
> 
> This is really slow and doesn't seem to work.
> 
> ARRAY TO
> COLLECTION($companycol;$CompanyUUID;"UUID";$alContactMySqlID;"MySQLUserID";$asName;"Name";$asAddress;"AddressLine1";$asCity;"Town";$asPostcode;"PostCode")
> 
> $col:=$companycol.distinct("MySQLItemID")
> 
> For each ($element;$col)
>       
>       $col2:=$companycol.query("MySQLItemID = :1";$element)
This line finds *all* items in $companycol matching the ID, and 

>       $col3.combine($col2)
this line adds *all* those found elements to $col3. So at the end, $col3 should 
be the same as $companycol. What you probably want is:

$col3.push($col2[0])

This will just add the first found element, not all the duplicates that were 
also found by .query(). You shouldn’t have to check whether you found any items 
since you’re querying on IDs you’ve extracted from the collection.
        
> End for each 

> $col.clear()
> $col2.clear()
> $companycol:=$col3
> $col3.clear()

You shouldn’t need to clear the collections either, unless you are going to use 
them again for something else. As local variables, they’ll be cleared when the 
method ends.

Jim Crate

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to