Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Cetin Basoz
 To: Matt Slay
  Where is Matt Slay?
 Alabama - United States
 Matt Slay
Subject: RE: Create collection of objects from cursor
Thread ID: 209443 Message ID: 209534 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Monday, December 29, 2008 1:16:51 PM         

> Do you know of a technique that will create a collection of objects where each object in the collection represents a row from a cursor?
> Basically, it would be like scattering a cursor to a collection of objects.
> Example:
> select * from ChildAlias;
> where fkey=ParentAlias.pkey;
> into cursor csrChildRecords
> Then, (pseudo code):
> scatter Cursor csrChildRecords to Collection collectionChildRecords
> or a method call like CreateCollectionFromCursor('CursorName', 'CollectionName')
> where the method would have a do/while loop that will create a collection, and then add an object to the collection for each row in the cursor.
> Have you seen thee need or application of such an approach?

Let me begin saying, of course I have seen a need(s) for such an approach and been using it for a long time.

use myTable
dimension myRows[reccount()]
 scatter name myRows[recno()] memo

is the skeleton (I prefer arrays over collection object). Another version that stems from that skeleton:
loMyRows = createobject('Empty')
addproperty(loMyRows, 'count', reccount())
addproperty(loMyRows, textmerge('row[<<reccount()>>]')
 scatter name loMyRows.Row[recno()] memo

Depending on your need getting the data as XML using XMLAdapter might be a better solution. ie:
Select * ;
  from customer ;
  where cust_id = 'BONAP' ;
  into Cursor crsCustomer nofilter

Select t1.* ;
  from orders t1 ;
  inner Join crsCustomer t2 On t1.cust_id = t2.cust_id ;
  into Cursor crsOrders nofilter
Index On cust_id Tag cust_id

Select t1.* ;
  from ordItems t1 ;
  inner Join crsOrders t2 On t1.order_id = t2.order_id ;
  into Cursor crsOrdDet nofilter
Index On order_id Tag order_id

Select customer
Set Relation To cust_id Into crsOrders In crsCustomer
Set Relation To order_id Into crsOrdDet In crsOrders Additive

Local loAdapter As Xmladapter,loAdapter2 As Xmladapter
loAdapter = Createobject('XMLAdapter')
loAdapter.AddTableSchema('crsOrders',  .F.,Strconv('MyOrders',12),'','',.F.,.F.,.T.)
loAdapter.AddTableSchema('crsOrdDet',  .F.,Strconv('MyOrderDetails',12),'','',.F.,.F.,.T.)
loAdapter.RespectNesting = .T.

Cetin Basoz


Create collection of objects from cursor Posted by Matt Slay @ 12/28/2008 10:27:57 PM
RE: Create collection of objects from cursor Posted by mike castillo @ 12/29/2008 2:20:07 AM
RE: Create collection of objects from cursor Posted by tushar @ 12/29/2008 7:21:01 AM
RE: Create collection of objects from cursor Posted by Boudewijn Lutgerink @ 12/29/2008 9:04:40 AM
RE: Create collection of objects from cursor Posted by Cetin Basoz @ 12/29/2008 1:16:51 PM