Re: Distinct Collection

2020-05-04 Thread Paul Dennis via 4D_Tech
Thanks Jim, Using OrderBy and push is exactly what I ended up doing. Its
faster and the orda code is simpler than managing a lot of arrays.
Paul



--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**
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
**

Re: Distinct Collection

2020-05-01 Thread James Crate via 4D_Tech
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. 

I forgot to show what I’d do. Querying every distinct ID is likely to be slow 
if there are many rows. This could be simplified a bit.


ARRAY TO 
COLLECTION($companycol;$CompanyUUID;"UUID";$alContactMySqlID;"MySQLUserID";$asName;"Name";$asAddress;"AddressLine1";$asCity;"Town";$asPostcode;"PostCode”)

// MySQLItemID is not in the ARRAY TO COLLECTION?

// Sort the collection
$companycol:=$companycol.orderBy(“MySQLItemID”)

$uniqueCol:=New collection
$lastID:=-1
For each ($element;$companycol)
 If ($lastID#$element.MySQLItemID)
   $lastID:=$element.MySQLItemID
   $uniqueCol.push($element)
 End if
End for each



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
**

Re: Distinct Collection

2020-05-01 Thread James Crate via 4D_Tech
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
**

Distinct Collection

2020-04-29 Thread Paul Dennis via 4D_Tech
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)
$col3.combine($col2)

End for each 

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

I've been looking through the documentation and the examples.finding it hard
going.

Thanks
Paul





--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**
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
**