How to sort b sequence? FW: Order of returned VArraySet rids when using FindLinked with a VArraySet arg.

Ed Kleban Ed at Kleban.com
Wed Dec 14 20:33:45 CST 2005




On 12/14/05 7:38 PM, "Ed Kleban" <Ed at kleban.com> wrote:

> 
> Ok, I'm guessing the question below is irrelevant because as my last email
> on the subject of "V4RB Confusion" notes, despite documentation errors to
> the contrary is probably is FindLinked method that both takes an (inSet as
> VArraySet) as an argument and returns a VArraySet as a result.  So I'm a bit
> lost on how to implement what I need.
> 
> I have two tables.
> 
> The first is TblItems  which has some miscellaneous fields.
> 
> The second is TblTree which keeps the MANY:MANY parent/child
> releationships and and sequence order of children for the records in
> TblItems.   
> 
> TblTree has 3 fields:
> 
>     fTreeParent as VObjectPtr  // Rid of parent in TblItems
>     fTreeChild as VObjectPtr   // Rid of child in TblItems
>     fTreeSeq as UShort         // Relative sequence number of child.
> 
> So I now want to implement a method that will return a list of the children
> in sequence order for a given parent.
> 
> First I get all the children records for a given parent:
> 
>     treeRidSet = TblTree.fTreeParent.FindLinked( _
>                        parentItemRid,TblTree, TblItems )
> 
> What I would like to then do is:
> 
>     // Sort records by sequence number:
>     orderedTreeRidSet = TblTree.Sort( treeRidSet, TblTree.fTreeSeq )
> 
>     // Retrieve TblItem Rids in the current sorted order:
>     orderedItemRidSet = _
>         TblTree.vlChildToItemLink.FindLinkedAsArraySet( _
>             orderedTreeRidSet, TblTree, TblItems )
> 
> However, there is no such call as FindLlinkedAsArraySet, and I'm not sure it
> would preserve the inSet order if there was.
> 
> So how do I do this?  I guess I could try and retrieve the child links
> first:
> 
>     unorderedChildBitSet = _
>         TblTree.vlChildToItemLink.FindLinkedAsBitSet( _
>             treeRidSet, TblTree, TblItems)
> 
>     // Perform painful, expensive conversion from BitSet to ArraySet
>     unorderedChildArraySet = VArraySet( unorderedChildBitSet )
> 
> But then how do I sort these based on the order of TblTree records in
> orderedTreeRidSet ?
> 
> This one just has me stumped.  The only solutions that come to mind are:
> 
> 1) Do all this much more slowly in SQL.  Yuck.
> 
> 2) Combine the TblTree fields into TblItems where I have a sufficent set of
> API calls to make this work... But now that TblTree is managing MANY:MANY
> parent/child relationships his just isn't feasible.
> 
> 3) Convince to you write ASAP a FindLinkedAsArraySet method that preserves
> the same order of records in the VArraySet result as the same order in the
> passed inSet argument.
> 

4) Ok, I figured out one possible way out of this predicament.   You can
execute a loop to replace every TblTreeRid in orderedTreeRidSet with the
corresponding TblItemRid from the same record, then return the
orderedTreeRidSet (which is then actually an orderedItemRidSet ):
  
  call cursorOnFTreeChild.updateFieldCursor
  for index as Integer = orderedTreeRidSet.count downTo 1
    treeRid = orderedTreeRidSet.itemAt( index )
    orderedTreeRidSet.ItemAt( index ) = _
        cursorOnFTreeChild.integerValue( treeRid, kNoUpdate )
  next
  
  return orderedTreeRidSet
 
> Do you have some other suggestions to offer?

And I'm still both open to more suggestions and curious if you are willing
to do (3) above :-)
 
> Thanks!
> --Ed
> 
>   




More information about the Valentina mailing list