Alpha Video Training
Results 1 to 8 of 8

Thread: Not fetching through a set

  1. #1
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    732

    Default Not fetching through a set

    I have a set called "EnterRegLogging", which has Parent "EnterRegInput" and a Child "Logging" on a one-to-many link.
    I am trying to get to each child record for each parent and do some processing.

    I found an example in the documentation and gave it a go.

    Code:
    trace.clear("test")
    set_ptr      = set.open_session("enterreglogging")
    Parent_ptr   = set_ptr.enterreginput
    child_ptr    = set_ptr.logging
    set_ptr.fetch_first()
    while .not. set_ptr.fetch_eof()
        child_reg = child_ptr.reg
        child_unique = child_ptr.unique
        child_ac_unique = child_ptr.ac_unique
        trace.writeln(rtrim(child_reg)+" has Unique "+child_unique+" with ac_unique of "+child_ac_unique,"test")
        set_ptr.fetch_next()
    end while
    set_ptr.close()
    the above script lists every child record for the first parent, but I cannot get it to do the rest. (my parent test table has 23 records and the child table has 155, each parent has varying number of child records (in my test file, between 0 and 70 for each parent).
    I think Im missing something here, but not sure what, Guidance would be appreciated.
    Last edited by Graham Wickens; 02-26-2019 at 07:57 AM. Reason: additional info
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  2. #2
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    732

    Default Re: Not fetching through a set

    I did try puting the set loop inside a loop of the parent records and got the same result.
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  3. #3
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default Re: Not fetching through a set

    Graham,

    The pointer problem.

    Code:
    set_ptr.fetch_first()
    while .not. set_ptr.fetch_eof()
    it will be the parent's pointer , Parent_ptr

  4. #4
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    732

    Default Re: Not fetching through a set

    OK, gave that a try, but same result

    Code:
    trace.clear("test")
    set_ptr      = set.open_session("enterreglogging")
    Parent_ptr   = set_ptr.enterreginput
    child_ptr    = set_ptr.logging
    Parent_ptr.fetch_first()
    while .not. parent_ptr.fetch_eof()
    	Parent_reg = parent_ptr.reg
    	child_unique = child_ptr.unique
    	child_ac_unique = child_ptr.ac_unique
    	trace.writeln(rtrim(parent_reg)+" has Unique "+child_unique+" with ac_unique of "+child_ac_unique,"test")
    	parent_ptr.fetch_next()
    end while
    set_ptr.close()
    still only the first Parent value with all 70 child records
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  5. #5
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default Re: Not fetching through a set

    Try this code from AlphaSports

    Code:
    dim cRecords as c=""
    dim ptr as p 
    dim sHdr as p 
    dim sItm as p 
    
    s = set.open_session("invoice.set")
    'on error goto 0 
    'get pointer to invoice_header table
    tih = s.invoice_header 
    
    'get pointer to invoice_items table
    tii = s.invoice_items 
    t2 = s.customer
    
    'tih.index_primary_put("")
    tih.fetch_first()
    while .not. tih.fetch_eof()
    	'msgbox("test",t2.lastname )
    	cRecords = cRecords+str(tih.recno() )+crlf()
    	tih.fetch_next()
    end while
    
    s.close()
    
    showvar(cRecords,"test")  'check the result

  6. #6
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    732

    Default Re: Not fetching through a set

    Same again, just first parent record
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  7. #7
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default Re: Not fetching through a set

    Well,

    How about change to active this " tih.index_primary_put("") " and also check the Set table name.

  8. #8
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    732

    Default Re: Not fetching through a set

    Quote Originally Posted by johnkoh View Post
    Well,

    How about change to active this " tih.index_primary_put("") " and also check the Set table name.
    John finally got it to work

    Code:
    dim cdata as c = ""
    dim shared set_ptr as P
    dim shared parent_ptr as p
    dim shared child_ptr as p
    set_ptr = set.open_session("enterreglogging.set")
    parent_ptr = set_ptr.enterreginput
    child_ptr  = set_ptr.logging
    tbl = table.current()
    filter = ".t."
    query.filter = "flattenquery("+filter+")"
    qry = parent_ptr.query_create()
    set_ptr.fetch_first()
    while .NOT. set_ptr.fetch_eof()
         cdata = cdata+child_ptr.reg+" "+child_ptr.When+" "+child_ptr.where+" "+child_ptr.unique+crlf()
      set_ptr.fetch_next()
    end while
    set_ptr.close()
    showvar(cdata,"test")
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

Similar Threads

  1. Another Fetching Question
    By Firemedic934 in forum Alpha Five Version 9 - Desktop Applications
    Replies: 12
    Last Post: 07-10-2009, 08:46 AM
  2. Fetching at a particular Level in a set
    By B Philip Gerber in forum Alpha Five Version 6
    Replies: 5
    Last Post: 02-22-2005, 05:17 PM
  3. Fetching in SQL
    By Gregory R. Zilliox in forum Alpha Five Version 6
    Replies: 13
    Last Post: 10-25-2004, 04:00 PM
  4. Fetching
    By BRIAN GRAY in forum Alpha Five Version 5
    Replies: 4
    Last Post: 11-26-2003, 07:46 AM
  5. Fetching
    By Trimcom in forum Alpha Five Version 5
    Replies: 3
    Last Post: 08-08-2003, 04:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •