Quantcast

Query not returning results when using positional parameters

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Query not returning results when using positional parameters

harjit@teslagovernment.com
Hi there,

I have the following query

 def currentUser = User.find('from User where enabled = (:a) AND ( emailAddress = (:e) OR altEmailAddress like (:e) )',
                [a: _enabled, e: _email.toLowerCase()])


I know there is data in the tables which should be returned, it doesn't seem to return any results. Is there anything wrong with the way I'm doing a like ?

Thanks

- Harjit
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Query not returning results when using positional parameters

burtbeckwith
You need to add the % characters yourself. Also, I'm not sure if the parens are affecting anything but I don't wrap named args in them unless they're required. So this should work:

   def currentUser = User.find('from User where enabled = :a AND ( emailAddress = :email OR altEmailAddress like :altEmail )',
                [a: _enabled, email: _email.toLowerCase(), altEmail: '%' + _email.toLowerCase() + '%'])

Burt

harjit@teslagovernment.com wrote
Hi there,

I have the following query

 def currentUser = User.find('from User where enabled = (:a) AND ( emailAddress = (:e) OR altEmailAddress like (:e) )',
                [a: _enabled, e: _email.toLowerCase()])


I know there is data in the tables which should be returned, it doesn't seem to return any results. Is there anything wrong with the way I'm doing a like ?

Thanks

- Harjit
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Query not returning results when using positional parameters

harjit@teslagovernment.com
Ahhh... For some reasons I thought using the like with positional parameters would generate the correct SQL

Harjit

On Jun 11, 2012, at 4:51 PM, burtbeckwith <[hidden email]> wrote:

> You need to add the % characters yourself. Also, I'm not sure if the parens
> are affecting anything but I don't wrap named args in them unless they're
> required. So this should work:
>
>   def currentUser = User.find('from User where enabled = :a AND (
> emailAddress = :email OR altEmailAddress like :altEmail )',
>                [a: _enabled, email: _email.toLowerCase(), altEmail: '%' +
> _email.toLowerCase() + '%'])
>
> Burt
>
>
> [hidden email] wrote
>>
>> Hi there,
>>
>> I have the following query
>>
>> def currentUser = User.find('from User where enabled = (:a) AND (
>> emailAddress = (:e) OR altEmailAddress like (:e) )',
>>                [a: _enabled, e: _email.toLowerCase()])
>>
>>
>> I know there is data in the tables which should be returned, it doesn't
>> seem to return any results. Is there anything wrong with the way I'm doing
>> a like ?
>>
>> Thanks
>>
>> - Harjit
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Query-not-returning-results-when-using-positional-parameters-tp4629915p4629933.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...