Bracketing in strong typed queries are broken?
 
Forums / SmartComponent Library - Developer Forum / Bracketing in strong typed queries are broken?

Bracketing in strong typed queries are broken?

3 posts, 0 answered
  1. Patrik Wikström
    Patrik Wikström avatar
    75 posts
    Registered:
    15 Oct 2018
    21 Mar
    Link to this post
    We are running a bit older SCL but did try to scan release notes but didn't catch any bugfixes regarding to this issue we've now noticed.
    https://consultingwerk.atlassian.net/wiki/spaces/SCL/pages/8094128/Strong-typed+Query+Support
    The bracketing is not working as expected and we noticed code changes in the Querybuilder class. For example this:
    oQuery = NEW CustomerQuery() .

    oQuery:Or (NEW CustomerQuery ():Country:Eq("USA"):And:City:Begins("Bost"),
               NEW CustomerQuery ():Country:Eq("DE"):And:City:Begins("Colog"))
           :And:CreditLimit:Lt(1000).

    MESSAGE oQuery:ToQueryString(FALSE)
        VIEW-AS ALERT-BOX.
    ...where we would expect to see brackets on both sides of the OR but that is not the case anymore.

    Is this still an issue or fixed in a more recent release?
  2. Mike Fechner
    Mike Fechner avatar
    352 posts
    Registered:
    14 Sep 2016
    21 Mar in reply to Patrik Wikström
    Link to this post
    What you get is 

    for each eCustomer where Country EQ "USA" AND City BEGINS "Bost" OR Country EQ "DE" AND City BEGINS "Colog" AND CreditLimit LT 1000

    which is the same as

    for each eCustomer where (Country EQ "USA" AND City BEGINS "Bost") OR (Country EQ "DE" AND City BEGINS "Colog") AND CreditLimit LT 1000

    due to boolean order of operands.

    if you want

    for each eCustomer where (Country EQ "USA" AND City BEGINS "Bost" OR Country EQ "DE" AND City BEGINS "Colog") AND CreditLimit LT 1000 

    then you need to code:

    using Consultingwerk.SmartComponentsDemo.OERA.Sports2000.*.

    var CustomerQuery oQuery.

    oQuery = new CustomerQuery() .
    oQuery:And (new CustomerQuery():Or (new CustomerQuery ():Country:Eq("USA"):And:City:Begins("Bost"),
                                        new CustomerQuery ():Country:Eq("DE"):And:City:Begins("Colog")),
                new CustomerQuery ():CreditLimit:Lt(1000)).

    message oQuery:ToQueryString(false).
  3. Patrik Wikström
    Patrik Wikström avatar
    75 posts
    Registered:
    15 Oct 2018
    21 Mar in reply to Mike Fechner
    Link to this post
    Thanks! I'll now see. I've been so used to explicitly tell by brackets which operands the OR is between so I've forgotten the operand precedence. Still I would say it was better and clearer before. ;)

    The result of examples on page https://consultingwerk.atlassian.net/wiki/spaces/SCL/pages/8094128/Strong-typed+Query+Support should be fixed at some point. :)
3 posts, 0 answered