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

Need help with query_create()

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

    Need help with query_create()

    I am struggling to delete child records from a set. I wrote some inline xbasic executed from a button to perform the delete. Whenever I execute the code I get an error message reading �no such field�. Can anyone please assist. I am fairly new at Alpha and if there is a better way of doing this please let me know

    Code:
    dim tbl_a as p
    dim tbl_b as p
    
    tbl_a = table.get("sort order")
    tbl_b = table.get("customer")
    
    query_filter = "tbl_b.customer_id <> ''"
    tbl_b.query_create()
    
    query.filter = "tbl_a.customer_id ='" + tbl_b.customer_id + "'"
    query.sort = ""
    
    tbl_a.query_create()
    
    tbl_a.delete_range()
    tbl_a.close()
    tbl_b.close()

    #2
    Re: Need help with query_create()

    You already have table pointers so the query.create() doesn't need references to them.

    Code:
    dim tbl_a as p
    dim tbl_b as p
    
    tbl_a = table.get("sort order")
    tbl_b = table.get("customer")
    
    query_filter = "customer_id <> ''"
    tbl_b.query_create()
    
    query.filter = "customer_id ='" + tbl_b.customer_id + "'"
    query.[COLOR="Red"][B]order[/B][/COLOR] = ""
    
    tbl_a.query_create()
    
    tbl_a.delete_range()
    tbl_a.close()
    tbl_b.close()
    Not sure what you are trying to accomplish.

    The lines

    query.filter = "customer_id ='" + tbl_b.customer_id + "'"
    tbl_a.query_create()

    say "filter the 'sort order' table for records matching the current value in the customer_id field in the customer table".

    It would take some sort of loop to read the customer_id field in the customer table, in each record, filter the sort order table on that value, delete the records from the sort order table.
    There can be only one.

    Comment


      #3
      Re: Need help with query_create()

      From what you describe, I would think this would work:
      Code:
      dim tbl_c as p   'child
      dim tbl_p as p   'parent
      dim vfilter as C
      
      tbl_p = table.get("customer")       'get() requires the table to be already open
      
      tbl_c = table.get("sort order")
      vfilter = "customer_id ='" + tbl_p.customer_id + "'"    'you don't need pointer to the child table in the filter.
      tbl_c.delete_range(vfilter)
      
      topprent:browse2.refresh()            ' guessing on the child browse name
      There is no need to close a table... you didn't open any, you got what was open.
      Mike W
      __________________________
      "I rebel in at least small things to express to the world that I have not completely surrendered"

      Comment


        #4
        Re: Need help with query_create()

        And one more possible problem if the initial script is going to be used at all is I believe

        Code:
        query_filter = "tbl_b.customer_id <> ''"
        tbl_b.query_create()
        should have a period not an underscore to work (query.filter)
        Code:
        query[SIZE=6][COLOR=Red].[/COLOR][/SIZE]filter = "tbl_b.customer_id <> ''"
        tbl_b.query_create()
        Mike
        __________________________________________
        It is only when we forget all our learning that we begin to know.
        It's not what you look at that matters, it's what you see.
        Henry David Thoreau
        __________________________________________



        Comment


          #5
          Re: Need help with query_create()

          Thank you Stan & Mike. New at xbasic and still getting the hang of it. I used Mike's solution and it works perfectly. Thank you for the explanation. I have a much better understanding.

          Comment


            #6
            Re: Need help with query_create()

            Mike, Mike and Stan,
            I was under the impression you couldn't use tbl pointers within the filter and order expresions. From the help:
            Note : The Query.Filter and Query.Order expressions cannot include references to the table pointer.
            Am I missing something???(as usual.)
            Ernie

            Comment


              #7
              Re: Need help with query_create()

              If you mean the line

              query.filter = "customer_id ='" + tbl_b.customer_id + "'"

              tbl_b.customer_id is not technically in the filter expression.

              In English this line reads

              Take the current value in the customer_id field in the table referenced by the pointer tbl_b.
              Quote that value.
              Concatenate that quoted value with the text "customer_id =" to yield a result like

              "customer_id = 'abc45' "

              Assign that result to the query.filter variable.

              I beleive the passage you quoted means you can't have

              "tbl_a.customer_id = 'abc45' "
              There can be only one.

              Comment


                #8
                Re: Need help with query_create()

                Stan,
                Thanks for the explanation. I just assumed that anything that used the "tbl_b" was the table pointer since it had been dimmed as p. So I am now assuming that that quote from the Help file means you can't use a reference to the table pointer on the "Left" side of the "=" sign. Is this correct?
                Thanks.
                Ernie

                PS: I seem to be using querys a bunch now in xbasic coding. I'm currently having a problem syntaxing the query.order expression based on two numeric fields, "ap_year" and ap_sortno.
                Have an index set up that uses: str(ap_year)+str(ap_sortno)
                Can't figure out how to get this syntaxed into the query.order expression. Help would be greatly appreciated.

                Comment


                  #9
                  Re: Need help with query_create()

                  quote from the Help file means you can't use a reference to the table pointer on the "Left" side of the "=" sign
                  Don't think so. You can't use table pointers in the query.filter expression. I didn't. You can build the query.filter expression out of anything you want. I did.

                  Remember, the query.filter expression is the end result, not the steps used along the way. If I had tried/wound up with

                  "customer_id = 'tbl_b.customer_id' "

                  it would have failed.



                  query.order = "str(ap_year)+str(ap_sortno)"

                  However you would write the filter in a report definition or a form filter expression, take that and put quotes around it. Take the result and see if it makes sense....

                  Does it have internal quotes, use \ to escape them.
                  Does it refer to variables, break them out of the expression and make Alpha use their values.

                  Suppose myvar = "a"
                  the expression "somefield = var->myvar" will never recognize that you don't mean the literal text var->myvar instead of the value in the variable myvar.

                  the expression "somefield = "+quote(var->myvar) tells Alpha to concatenate the text "somefield = " with the text contained in the variable myvar
                  There can be only one.

                  Comment


                    #10
                    Re: Need help with query_create()

                    why is it not "ap_year + ap_sortn" ?
                    Mike W
                    __________________________
                    "I rebel in at least small things to express to the world that I have not completely surrendered"

                    Comment


                      #11
                      Re: Need help with query_create()

                      Wouldn't two numbers simply be added together?

                      2007 + 10 would sort the same as 2001 + 16
                      There can be only one.

                      Comment


                        #12
                        Re: Need help with query_create()

                        yup, and that is exactly what it did. I don't use numeric fields very much at all (as it shows). And I'm guessing that Ernie's two fields don't actually need to be numeric, either.

                        The "str(ap_year)+str(ap_sortno)" is working to order the table in my hands.
                        Mike W
                        __________________________
                        "I rebel in at least small things to express to the world that I have not completely surrendered"

                        Comment


                          #13
                          Re: Need help with query_create()

                          I will swear on a stack of Bibles that that was what I had tried:
                          "str(ap_year)+str(ap_sortno)"
                          But kept getting some error about "ap_sortno" not found. So ventured off into space somewhere. Now I just copied and pasted that code from your post and it works. Had to have been a miss type on my part, I guess.
                          Really appreciate the help.
                          Ernie

                          Comment

                          Working...
                          X