The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Wrong query generated when using ToUpper / Wrong operator precedence?

Last post 06-27-2008, 7:32 AM by dguaraglia. 4 replies.
Sort Posts: Previous Next
  •  06-27-2008, 3:32 AM 10018

    Wrong query generated when using ToUpper / Wrong operator precedence?

    Hi guys!

    I've just found an small error, and was wondering whether there is a work around it. I have some code that loads contacts for a client, and it's a company policy to capitalize last names in order to avoid confusions when a consultant has to call someone over the phone. This is the code I'm using to retrieve the contacts in a way I can put them in a ComboBox:

     

    Code:
    1    Dim contacts As New Data.ContactsCollection
    2 Dim q As Data.ContactsQuery = contacts.Query
    3 q.Select((q.LastName.ToUpper + " " + q.FirstName).As("Name"), q.Id).OrderBy("Name", EntitySpaces.Interfaces.esOrderByDirection.Ascending)
    4 q.Where(q.ClientID = ClientID)
    5 q.Load()
    And this is the generated SQL:
    Code:
    SELECT UPPER(CONCAT(`LastName`,' ',`FirstName`)) AS 'Name',`Id`  FROM `contacts` WHERE `ClientID` = ?ClientID1  ORDER BY `Name` ASC
    As you can see the UPPER function is wrapping both the first name and the last name, which is not what I want.
    Any ideas on a work around? I tried wrapping the q.LastName.ToUpper with parenthesis, but still didn't work.
     
    Cheers,
    David  
  •  06-27-2008, 6:53 AM 10022 in reply to 10018

    Re: Wrong query generated when using ToUpper / Wrong operator precedence?

    Are you using ES2007? That looks like a bug that was fixed in ES2008.
    David Neal Parsons
    www.entityspaces.net
  •  06-27-2008, 7:01 AM 10023 in reply to 10022

    Re: Wrong query generated when using ToUpper / Wrong operator precedence?

    Almost forgot... As a work-around in ES2007, you'd have to use the inline raw SQL technique:

    Code:
    collection.Query.Select( _
        "<CONCAT(UPPER(`LastName`), ' ', `FirstName`) AS 'Name'>")

    David Neal Parsons
    www.entityspaces.net
  •  06-27-2008, 7:02 AM 10024 in reply to 10022

    Re: Wrong query generated when using ToUpper / Wrong operator precedence?

    Yes I am. I'd be using ES2008 wasn't it for the error I describe here:

    http://community.entityspaces.net/forums/thread/9993.aspx

    If I get a usable solution/work-around for that thread, then I'll use ES2008 to finish this project, but if that takes too long I'll probably resort to creating a view in the server, but that quite defeats the purpose of having DynamicQueries. 

  •  06-27-2008, 7:32 AM 10026 in reply to 10023

    Re: Wrong query generated when using ToUpper / Wrong operator precedence?

    Hmm... yup, that could work. The problem is I'm writing the application using MySQL as the DB, but most probably my company will push to deploy it on SQL Server 2005. Yes, I know I should always develop using the DB back-end I plan to use, but SQL Server Express is a hog and, besides, ES insulates me from that kind of crap.

    I'll still wait to see what comes up of the ES2008 problem, I'm really looking forward to using the new version :)

View as RSS news feed in XML