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

Set Design/Searching

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

    Set Design/Searching

    Here is my dilema, I setup my tables and sets in what I thought was logical but now when I need to search for something, I am at a loss. Perhaps there is an easy way but I can't think of it.

    The short of it is:

    Main Table of Set: Reservation
    Fields: Resnum Tailnum

    Child one to many: Resdetails
    Linking Field: Resnum
    Logical Field: Complete

    The reservation has a number which links the reservation details to it. The "Tail Number" (tailnum) of the aircraft is associated with the reservation. People substitute aircraft all the time so my thought was to only store the tailnumber with the reservation then having to rely on cascading changes. As the items in the resdetails file are finished they are marked complete using the logical.

    Now, When entering a new record into a set I want to check to see if a particular tailnumber has any resdetails where complete is .f., since tail number is not stored in the resdetails I cannot use an index and thus exist() or dbsum() etc to check. As there are multiple reservations for any tailnumber, it is not as simple as a lookup of the resnum. I hope this makes sense. I thought I would simplify the design and not duplicate info, but now an easy lookup seems out of my reach. Any thoughts?

    #2
    Re: Set Design/Searching

    Hi John

    Have you tried creating a "reverse" set ie: Make Resdetails the primary table and the reservation the child table on a 1:1 link?

    Glen
    Glen Schild



    My Blog

    Comment


      #3
      Re: Set Design/Searching

      Originally posted by glenschild View Post
      Hi John

      Have you tried creating a "reverse" set ie: Make Resdetails the primary table and the reservation the child table on a 1:1 link?

      Glen
      I do this when I am making forms and reports. When creating a new record, I need to check if there are any open (complete=.f.) for a given tail number, the problem with creating an xbasic expression is the tail number is not included in the table to search. Exist() and dbcount() rely on an index and since the field to search is not there it will not work. I cannot use a lookup as again the field to search does not exist only in a relational set. This is my issue that I cant solve.

      Comment


        #4
        Re: Set Design/Searching

        Try this function. I think I have the names right. Save the function in the code tab and then call it where you want to do the checking. The function takes the Tailnum value and returns true if it it finds a false value ie not complete. As the function name implies it returns true if there are any in-completes.

        This is basically what Glen suggested but the set is created on the fly. The child(Reservation) is filtered on the Tailnum and then the parent (Resdetails) is filtered on the Complete field. Then just do a count.

        Code:
        FUNCTION Tailnum_has_incomplete as L(Tailnum as C)
        	Tailnum_has_incomplete = .f.
        	
        	DIM tbl_P as p
        	tbl_P = table.open("Resdetails",TABLE_MODE_INFORMATIONAL)
        	dim tbl_C as p
        	tbl_C = table.open("Reservation",TABLE_MODE_INFORMATIONAL)
        	dim relation as p
        	relation.link_type = LINK_MANY+LINK_MATCH_ONLY
        	relation.index_child = tbl_C.order("Resnum","Tailnum = '" + Tailnum + "'","")
        	relation.order_parent = "Resnum"
        	relation.ref_integrity = REFERENTIAL_INTEGRITY_NONE
        	tbl_P.relation_add(tbl_C,relation)
        	tbl_P.order("",".not. Complete")
        	tbl_P.fetch_first()
        		
        	dim count as N = 0
        	WHILE .NOT. tbl_p.fetch_eof()
        		count = count + 1
        		tbl_p.fetch_next()
        	END WHILE
        	
        	tbl_P.relation_drop(tbl_C)
        	tbl_C.close()
        	tbl_P.close()
        		
        	Tailnum_has_incomplete = (count > 0)
        	
        END FUNCTION
        Tim Kiebert
        Eagle Creek Citrus
        A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

        Comment


          #5
          Re: Set Design/Searching

          Tim,

          Thanks for this, I will give this a go. This is well beyond what I am capable of, so it is much appreciated, I'll report back.

          Follow Up:

          Worked perfectly, I understand most of it, but I am trying to figure some of the dynamics. It is much appreciated. Its great to see a set created on the fly and then stepped through. It never occured to me. Thanks again, you are brilliant.

          Comment


            #6
            Re: Set Design/Searching

            Tim,

            Again, thank you, and it has been working perfectly, but I needed to add another filter and that being ".not. cancel" to what I am counting. I assume I would add that to

            tbl_P.order("",".not. Complete") and change it to:
            tbl_P.order("",".not. Complete .and. .not. cancel")

            but then I started trying to really understand the dynamic of what was going on. This is an order statement, not a filter. I thought this was filtering the on the fly set for only records that are "not complete" and then I looked at the while statement

            WHILE .NOT. tbl_p.fetch_eof()
            count = count + 1
            tbl_p.fetch_next()
            END WHILE

            and it seems in my limited mind that this is counting all the records, but I know this function works so something is happening in this to make it work and it is not as I think. I thought too that once I get to the first find of a not complete and not canceled record and be done with it. I hope this makes sense, I just am not sure what is exactly happening here. Also the the line:

            Tailnum_has_incomplete = (count > 0)

            does this change the above variable to .t. if the count is>0? I just didn't understand it as it is written. Thanks again.

            Comment


              #7
              Re: Set Design/Searching

              A glance at the documentation showed me

              <INDEX> as P = <TBL>.ORDER( Order_Expression as C [, Filter_Expression as C ] )

              So the usage Tim provided (tricky and non intuitive) uses the tbl.order() method to filter the table while leaving the order as is.

              I would recomend you use it as

              tbl_P.order("","(.not. Complete) .and. (.not. cancel)")

              to force the evaluation of the logicals the way you want
              There can be only one.

              Comment


                #8
                Re: Set Design/Searching

                Does anyone know anything about, when to use or reference to TABLE_MODE_INFORMATIONAL
                The only place I can find is in the editor when entering table.open mode parameter - no explanation

                Comment


                  #9
                  Re: Set Design/Searching

                  Stan,

                  Thanks, ill try that, but I was also thinking to make it more efficient, is there a way just to count the number of records in this set on the fly, or as soon as it finds just one record to stop? I do not need to know how many just if any exist that meet the criteria.

                  Comment


                    #10
                    Re: Set Design/Searching

                    is there a way just to count the number of records in this set on the fly
                    A5_GET_RECORDS_IN_QUERY() returns a count of records matching the supplied query.

                    IN the section

                    dim count as N = 0
                    WHILE .NOT. tbl_p.fetch_eof()
                    count = count + 1
                    tbl_p.fetch_next()
                    END WHILE

                    you could

                    dim count as N = 0
                    WHILE .NOT. tbl_p.fetch_eof()
                    count = count + 1
                    tbl_p.fetch_next()
                    if count > 0
                    exit while
                    end if
                    END WHILE
                    There can be only one.

                    Comment


                      #11
                      Re: Set Design/Searching

                      Stan,

                      That's very easy actually, I should have seen this, thank you very much.

                      Comment


                        #12
                        Re: Set Design/Searching

                        Now a rub...

                        tbl_P.order("","(.not. Complete) .and. (.not. cancel)")

                        because "cancel" is in the child table which is tbl.c by reference.

                        I don't think I can use this field this way, I'll try to play with it.

                        Later...

                        I just added another order statement:

                        tbl_C.order("",".not. cancel")

                        under the other and all seems to be working now. Thanks for your help.
                        Last edited by johngtatp; 10-01-2014, 02:53 PM.

                        Comment


                          #13
                          Re: Set Design/Searching

                          Correct, did not read closely enough.

                          Try changing relation.index_child = tbl_C.order("Resnum","Tailnum = '" + Tailnum + "'","")

                          to

                          relation.index_child = tbl_C.order("Resnum","Tailnum = '" + Tailnum + "' .and. (.not. Cancel)","")
                          There can be only one.

                          Comment


                            #14
                            Re: Set Design/Searching

                            What do you know, worked like a champ!, Thanks so much.

                            Comment

                            Working...
                            X