Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Help with Query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with Query

    The below code fragment is supposed to skip through 3 records in the parent table (t_ftps) and find the corresponding child record in t_ftpinfo.

    However, I can't get it to skip through the parent records, even though it indicates that there are 3 matching records as verified by q_ftps.records_get().

    Code:
    	t_ftps = table.open("app_ftps")
    	t_ftpinfo = table.open("ftp_info")
    	q_ftps = t_ftps.query_create("","pk_app ="+s_quote(pk_app2update))
    	q_ftpinfo = t_ftpinfo.query_create("","pk_ftpinfo = "+s_quote(t_ftps.Pk_ftpinfo))
    	n_ftps = q_ftps.records_get()
    	msgbox("FTP sites assigned to this app:  "+convert_type(n_ftps,"c"))
    	p_ftps = q_ftps.find_first()
    	for i = 1 to n_ftps
    		q_ftpinfo.find_first()
    		ui_msg_box("Sites","Site #"+convert_type(i,"C")+" to update is "+alltrim(t_ftpinfo.desc),ui_information_symbol)
    		q_ftps.find_next(p_ftps)
    		ui_msg_box("APP_FTPS","Next site is "+t_ftps.Pk_ftpinfo)
        next
    The line q_ftps.find_next(p_ftps) does not appear to be moving to the next matching record in the parent table. What am I doing wrong??? I wish there were better examples in the help file.
    John J. Fatte', CPA
    PRO-WARE, LLC
    Omaha, NE 68137

  • #2
    Re: Help with Query

    John, this line looks wrong:

    q_ftps.find_next(p_ftps)

    I don't think this method takes an argument. Shouldn't it be

    q_ftps.find_next()

    ??

    If that doesn't get you going then take a minute and rewrite the sequence in english, without using Alpha Five commands or statements. I'm having trouble discerning what your goal is as you step through the loop.

    Comment


    • #3
      Re: Help with Query

      Hi John,

      If you are trying to find all child records that belong to a parent then you would need to have a nested loop. I have shown the code here that I needed to give a row number to all child records before the application went live. While this code itself is not relevant to you at this time, it demonstrates how it works its way through the parent table, then works its way through the child table and processes each corresponding child record.

      Note the use of the While and End While loop.
      Code:
      'This script is designed to be used as a global script and should be run once from the 
      'Control Panel. Create a numeric field in the invoice2 table called line_number
      
      dim invh as p
      dim tbl as p
      dim linecount as n
      dim idx as p
      dim invnum as n
      dim qry as p
      dim nummy as n
      dim recs as n
      
      invh=table.open("temp2_2") 'the parent table in the set - if you ran this outside of the set
                                                    'it would renumber all invoice line items 
      on error goto errors 
      invh.fetch_first()
      while .not. invh.fetch_eof()
       linecount=0 'Reset the linecount field everytime another parent record is fetched
       
       nummy=invh.job_number 'Populate variable with invoice number fields from the invoice_header table
       'ui_msg_box("",(nummy)+"") 'Can be commented out. Only shows the Invoice_Number value of the Invoice_header table
       tbl=table.open("supp2")
        query.filter="sup_id=var->nummy"
        query.order="sup_id"
       query.options="N"
       query.decription="Number Item Lines"
       qry=tbl.query_create()
       recs=qry.records_get()
       'ui_msg_box("",str(recs)+"") 'Can be commented out. Shows how many child records related the the Invoice_header->Invoice_number field
          tbl.fetch_first()    
        while .not. tbl.fetch_eof()
         linecount=linecount+1     'Start the count at one first time through the while loop
          tbl.change_begin()    'Put child table into change mode
            tbl.line_number=padl(ltrim(str(linecount,2,0)),2,"0")  'populate the value of the line_number field
           tbl.change_end(.t.)    'end the change mode     
          tbl.fetch_next()     'fetch until last matching child record has been fetched
       end while  
      tbl.close()   'close the child (invoice_items) table  'fetch the next parent record
      invh.fetch_next() 'fetches the next record from the parent table
      end while
      invh.close()
      
      on error goto errors 
      end 
      errors:
      err_msg = error_text_get(error_code_get())
      line = error_line_number_get()
      script = error_script_get()
      ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
      end
      Hope this gives you a different look at what you are trying to achieve.
      Regards
      Keith Hubert
      Alpha Guild Member
      London.
      KHDB Management Systems
      Skype = keith.hubert


      For your day-to-day Needs, you Need an Alpha Database!

      Comment


      • #4
        Re: Help with Query

        Keith

        Thanks for the code segment. One thing I noticed is that you didn't use a pointer for the query. The help file for "query.find_next(ptr)" leads one to believe that you have to use a pointer so that (presumably) the query knows where it left off.

        I'm really just trying to navigate through the parent table which has been filtered based on a key value. Then the parent table needs to lookup additional data in a child table which is not filtered at tall.

        I'll try your code and see if it works. Thanks again.
        John J. Fatte', CPA
        PRO-WARE, LLC
        Omaha, NE 68137

        Comment


        • #5
          Re: Help with Query

          John, I find it useful to use nested loops and no queries in this situation.

          In pseudo code I will
          Code:
             - open both tables
             - set the primary index in each to the link field that relates the two tables
             -fetch the first record that matches the desired link field value in the 
                      parent table
                    - then loop through the related child table records, fetching one at a 
                       time
                    - stop when the fetched child rec has the wrong key or you've 
                      fetched past eof
              - then loop back to get the next primary table record
              - stop when the next primary table record has a key that doesn't match 
                    (or - you fetch past the eof)
              - close both tables
          Of course the nested loop is not needed if the link is one to one.

          Comment


          • #6
            Re: Help with Query

            Originally posted by Tom Cone Jr View Post
            John, I find it useful to use nested loops and no queries in this situation.

            In pseudo code I will
            Code:
               - open both tables
               - set the primary index in each to the link field that relates the two tables
               -fetch the first record that matches the desired link field value in the 
                        parent table
                      - then loop through the related child table records, fetching one at a 
                         time
                      - stop when the fetched child rec has the wrong key or you've 
                        fetched past eof
                - then loop back to get the next primary table record
                - stop when the next primary table record has a key that doesn't match 
                      (or - you fetch past the eof)
                - close both tables
            Of course the nested loop is not needed if the link is one to one.
            In this case, I don't think of this as a query. It's more a filter of the records to avoid using "if" statements to eliminate records that I don't want. But I can see why you might avoid using a query. The problem is, don't you have to in the case of a report that should only include filtered records?
            John J. Fatte', CPA
            PRO-WARE, LLC
            Omaha, NE 68137

            Comment


            • #7
              Re: Help with Query

              In this case, I don't think of this as a query. It's more a filter of the records to avoid using "if" statements to eliminate records that I don't want. But I can see why you might avoid using a query. The problem is, don't you have to in the case of a report that should only include filtered records?
              Maybe. Depends upon your needs and your goal, both of which remain a mystery to me.

              Comment

              Working...
              X