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

filter expression is not logical

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

    filter expression is not logical

    I keep getting a msg that says : query filter expression is not logical after the tbl.query_create() line.
    is something wrong with this code ?

    Thanks
    dim global tick as N
    tbl = table.open("tracking")
    tick=VAL(ui_get_number("FUJITICKETNUMBER","Enter Ticket Number","0","00000000"))
    query.description="ticket"
    query.filter = "TRACKING->FUJITICKETNUMBER=VAR->tick"
    query.option="I"
    tbl.query_create()
    :Form.load("main")

    #2
    RE: filter expression is not logical

    Suggest you go to Learnalpha.com and **PRINT** the following 2 articles (both articles and the numerous examples included have saved me numerous hours of agony setting up queries).

    "Query Filters Alternative...." by Tom Cone
    "Mysteries of Query & Lookup Syntax" by Dr. Wayne

    Just looking at your example I would suggest something like this:
    '"+var->tick+"'. Remember the entire expression must evaluate to characters.
    -Barry

    Comment


      #3
      RE: filter expression is not logical

      Anis,

      I'm 1st going to assume TRACKING->FUJITICKETNUMBER is a numeric field. Assuming it is, you want to compare it to another number, as you tried to. You even defined "tick" as a global numeric, which was a correct attempt. However, the query operation does not know about global variables (although it probably should). So the correct method would be


      tbl = table.open("tracking")
      tick=VAL(ui_get_number("FUJITICKETNUMBER","Enter Ticket Number","0","00000000"))
      query.description="ticket"
      query.filter = "TRACKING->FUJITICKETNUMBER="+LTRIM(STR(tick))
      query.option="I"
      tbl.query_create()
      :Form.load("main")

      Regards,

      Ira J. Perlow
      Computer Systems Design & Associates
      [email protected]
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        RE: filter expression is not logical

        I just tried your code Ira and I got the same message. Filter expression is not logical.
        You're right; the ticketnumber field is numeric field and so tick.

        Comment


          #5
          RE: filter expression is not logical

          While it may not be of much help, I just went through the same process this weekend. I used the interactive window to trace the values that the filter expression evaluates to to come up with the syntax that works. The article by Tom Cone is an excellent place to look for query syntax.

          Finally, you should turn on the recorder window, and record the expression that a manual query using the values that you want looks like. I then pasted the information into my script, and ... problems solved (mostly) :?) Robert.

          Comment


            #6
            RE: filter expression is not logical

            That's exactly what I did, I recorded the expression and copied it to the Button. If you look at the script, nothing seems to be out of order, other scripts work exactly the same way.

            Comment


              #7
              RE: filter expression is not logical

              Below is a script that is on a button on a form that resembles yours. This code works. I really think yours should work also unless there is different behavior. Try
              tb1.FUJITICKETNUMBER = var->tick
              John


              'rem find unpaid balance

              DIM CONTENTS as C
              DIM SHARED CLIMAN as C
              DIM SHARED NEWAMOUNT as N

              TB1 = TABLE.CURRENT()
              TB1.index_primary_put("CLIENT_N1")

              CLIMAN = ui_get_number("Enter invoice amount","Enter Amount")
              NEWAMOUNT = VAL(CLIMAN)

              if NEWAMOUNT = 0 then
              goto thatsall
              end if
              CONTENTS = "Unpaid Balance Search"
              query.description = CONTENTS
              query.order = "clinv->CLIENT_NO"
              query.filter = "clinv->BALANCE = var->NEWAMOUNT"
              query.options = "I"
              TB1.query_create()

              thatsall:
              end

              Comment


                #8
                RE: filter expression is not logical

                Thanks for all the help.
                Finally found it. the line:query.filter = "TRACKING->FUJITICKETNUMBER="+LTRIM(STR(tick))
                should have "tracking" in lower case.

                Comment


                  #9
                  RE: filter expression is not logical

                  Ira,
                  I'm a little confused. I understand why yours worked, but take a look at the script above (my message). This script works, I ran it before I posted it. The two scripts are nearly identical. The query in my case does seem to recognize the variable and I have instances of queries with variables in a number of places. I wonder if there was something conflicting with the "fieldname" or the "variable name" (index,calc field or other) that caused this particular query not to work rather than a query's inability to deal with variables. Or is something going on in my script that I am not seeing.
                  John

                  Comment


                    #10
                    RE: filter expression is not logical

                    John,

                    Your method should work with the VAR inside the quotes, but since Anis was having problems, I suggested not having it evaluated in the expression, which may have potentially been the problem. Nevertheless, as I'll try to explain, my method should be the way to always do it.

                    For the purposes of the query filter expression, the VAR value is a constant. In other words, it does not change between 1 record and the next as the query process takes place. Placing the VAR as a name forces Alpha 5 to evaluate the constant for every record. Let's use my example here (which uses character values);

                    dim global varname as C
                    varname="abc"
                    query.filter="charfieldname=trim(var->varname)"

                    For each record A5 must get the value of varname, trim it, then compare it to charfieldname.

                    Now suppose we do it my way

                    varname="abc "
                    query.filter="charfieldname='"+trim(var->varname)+"'"

                    In this 2nd case, the query.filter evaluates to

                    query.filter="charfieldname='abc'"

                    There are several advantages to the 2nd method.

                    1. No use of a global variable
                    2. The final expression is simpler, meaning the query will be significantly faster
                    3. Alpha 5 potentially could apply LQO (Lightning Query Optimization) if the charfieldname was indexed.

                    Since variables will always be constant (is that an oxymoron???) in the context of the expression of the query, there is nothing gained by putting in the variable name.

                    There is one exception possibly, but might be very version specific. A constant (like "abc") might take longer to access than a variable that had been set to that value. In that case, using the variable in place of the constant might be slightly faster, but that would definitely preclude potential use of LQO. The amount to be gained in this case is probably extremely small.

                    Regards,

                    Ira J. Perlow
                    Computer Systems Design & Associates
                    [email protected]
                    Regards,

                    Ira J. Perlow
                    Computer Systems Design


                    CSDA A5 Products
                    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                    CSDA Barcode Functions

                    CSDA Code Utility
                    CSDA Screen Capture


                    Comment


                      #11
                      RE: filter expression is not logical

                      Thanks, Ira! Put this in the book!

                      Comment


                        #12
                        RE: filter expression is not logical

                        To All,

                        With a little e-mail prompting with John, here is some cool stuff I found to add to the above.

                        Apparently, when you run the query, the query.filter has it var->variablename changed to a constant text string if it is character type. If it it is logical type, it is untouched. Thus (for the character case) if the filter is

                        varname="abc"
                        query.filter="fieldname=trim(var->varname)"

                        after the query it becomes
                        query.filter="fieldname=trim("abc")"

                        implying that A5 is smart enough to at least substitute the constant.

                        However, testing also indicated that there is a small amount of overhead associated with substituting the constant.

                        The reason I placed trim() in the test is to illustrate the important difference so that LQO would and would not take place based upon methods.

                        So to repeat and reiterate,

                        1. No use of a global variable (global variables should only be used when absolutely required)
                        2. The final expression is simpler, meaning the query will be significantly faster
                        - In the trivial case this has little importance. However if the part of the expression "trim(var->varname)" were alot more complex (but still evaluating to a constant), then it could make a big difference.
                        3. Alpha 5 potentially could apply LQO (Lightning Query Optimization) if the fieldname was indexed and the expression were acceptable, e.g.

                        query.filter="between(fieldname,"+chr(34)+trim(var->varname)+chr(34)+","+chr(34)+trim(var->varname)+chr(34)+")"

                        With LQO in a test case with 35000 records, it took .44 sec instead of 4.34 seconds.

                        Those wishing to try some variations, here is some code I created. Change the code as indicated to reflect your database table and indexed field. View the results in the trace window.


                        ' Change the tablename, char comparison value and
                        ' comparison field below (Search for CARID below and change. This field is indexed)
                        Tablename="datatabl"
                        dim global chr as C
                        char="FEDE"

                        '-------------------------

                        dim global filt as L
                        dim global filt1 as L
                        filt=.T.
                        filt1=.T.

                        query.description = "Query Speed Test"
                        query.order=""
                        query.options="I"

                        query.filter=".T."
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="var->filt"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="var->filt1.and..T."
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="var->filt1.and.var->filt"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="Carid==trim(var->char)"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="Carid==trim(var->char)"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        'query.filter="Carid=="+chr(34)+trim(char)+chr(34)
                        query.filter="between(Carid,"+chr(34)+trim(char)+chr(34)+","+chr(34)+trim(char)+chr(34)+")"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="between(Carid,trim(var->char),trim(var->char))"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        query.filter="between(Carid,var->char,var->char)"
                        tbl=table.open(Tablename)
                        trace.writeln("Before Query.Filter="+chr(34)+query.filter+chr(34))
                        t1=now()
                        ndx=Tbl.query_create()
                        t2=now()
                        trace.writeln("After Query.Filter="+chr(34)+query.filter+chr(34))
                        reccnt=ndx.records_get()
                        ndx.drop()
                        tbl.close()
                        trace.writeln("Query.Filter="+chr(34)+query.filter+chr(34)+" Rec Count="+LTRIM(STR(reccnt))+"
                        Time="+LTRIM(STR(t2-t1,15,2)))
                        trace.writeln("")

                        END


                        Regards,

                        Ira J. Perlow
                        Computer Systems Design & Associates
                        [email protected]
                        Regards,

                        Ira J. Perlow
                        Computer Systems Design


                        CSDA A5 Products
                        New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                        CSDA Barcode Functions

                        CSDA Code Utility
                        CSDA Screen Capture


                        Comment


                          #13
                          RE: filter expression is not logical

                          Ira,
                          Fascinating lesson on the proper use of expressions in a query. I have always struggled with the proper syntax when using a variable in the filter expression. After looking at your examples and playing with expression examples and sending the results to the trace window, the light finally came on. The concept that the filter expression result is just a line of text just didn't seem right. Fantastic and thanks for the clear explanation!

                          Jerry

                          Comment


                            #14
                            RE: filter expression is not logical

                            Ira,

                            I agree with Jerry. That little exercise was very interesting.

                            John

                            Comment

                            Working...
                            X