findAllBy with params?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

findAllBy with params?

Stephan.Schmidt
Hello,

how do I pass parameters to findAllByLike in a safe way?

results = Book.findAllByTitleLike("%Hobbit%")

Is there a

results = Book.findAllByTitleLike("%?%", "Hobbit") ?

bye
-stephan
Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

graemer
Hi Stephan,

Yes there is it takes a groovy list:

results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )

Cheers
Graeme

On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:

> Hello,
>
> how do I pass parameters to findAllByLike in a safe way?
>
> results = Book.findAllByTitleLike("%Hobbit%")
>
> Is there a
>
> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
>
> bye
> -stephan
>
Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

Stephan.Schmidt
Hmm. This does not find any Books.

repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find  
any Repos, but

SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the repo.

Any ideas?

bye
-stephan

> Hi Stephan,
>
> Yes there is it takes a groovy list:
>
> results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
>
> Cheers
> Graeme
>
> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>> Hello,
>>
>> how do I pass parameters to findAllByLike in a safe way?
>>
>> results = Book.findAllByTitleLike("%Hobbit%")
>>
>> Is there a
>>
>> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
>>
>> bye
>> -stephan
>>

Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

graemer
Ah sorry i was talking rubbish. This is not supported in dynamic
method expressions at the moment and is not really necessary as
internally it uses the Hibernate Criteria API, so is safe anyway. If
you want this feature please raise an issue, otherwise in the meantime
you can use HQL for your example:

repos = Repo.findAll("from Repo where name like '%?%'", ["SnipSnap"])

Cheers
Graeme

On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:

> Hmm. This does not find any Books.
>
> repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find
> any Repos, but
>
> SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the repo.
>
> Any ideas?
>
> bye
> -stephan
>
> > Hi Stephan,
> >
> > Yes there is it takes a groovy list:
> >
> > results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
> >
> > Cheers
> > Graeme
> >
> > On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> >> Hello,
> >>
> >> how do I pass parameters to findAllByLike in a safe way?
> >>
> >> results = Book.findAllByTitleLike("%Hobbit%")
> >>
> >> Is there a
> >>
> >> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
> >>
> >> bye
> >> -stephan
> >>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

Stephan.Schmidt
def repos = Repo.findAll("from Repo where name like '%?%' ", [ "Pool" ])

This creates:

Message: java.lang.IndexOutOfBoundsException: Remember that ordinal  
parameters are 1-based!
Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal  
parameters are 1-based!

bye
-stephan


> Ah sorry i was talking rubbish. This is not supported in dynamic
> method expressions at the moment and is not really necessary as
> internally it uses the Hibernate Criteria API, so is safe anyway. If
> you want this feature please raise an issue, otherwise in the meantime
> you can use HQL for your example:
>
> repos = Repo.findAll("from Repo where name like '%?%'", ["SnipSnap"])
>
> Cheers
> Graeme
>
> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>> Hmm. This does not find any Books.
>>
>> repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find
>> any Repos, but
>>
>> SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the repo.
>>
>> Any ideas?
>>
>> bye
>> -stephan
>>
>>> Hi Stephan,
>>>
>>> Yes there is it takes a groovy list:
>>>
>>> results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
>>>
>>> Cheers
>>> Graeme
>>>
>>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>>>> Hello,
>>>>
>>>> how do I pass parameters to findAllByLike in a safe way?
>>>>
>>>> results = Book.findAllByTitleLike("%Hobbit%")
>>>>
>>>> Is there a
>>>>
>>>> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
>>>>
>>>> bye
>>>> -stephan
>>>>
>>
>>

--
   Stephan Schmidt
   [hidden email]

   PRESS ON. Nothing in the world can take the place of persistence.
   Talent will not; nothing in the world is more common than  
unsuccessful
   men with talent. Genius will not; unrewarded genius is almost a  
proverb.
   Education will not; the world is full of educated derelicts.  
Persistence
   and determination alone are omnipotent. - Calvin Coolidge


Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

graemer
On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> def repos = Repo.findAll("from Repo where name like '%?%' ", [ "Pool" ])
>
> This creates:
>
> Message: java.lang.IndexOutOfBoundsException: Remember that ordinal
> parameters are 1-based!
> Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal
> parameters are 1-based!
Woopss :-) Can you raise an issue please!

Graeme

>
> bye
> -stephan
>
>
> > Ah sorry i was talking rubbish. This is not supported in dynamic
> > method expressions at the moment and is not really necessary as
> > internally it uses the Hibernate Criteria API, so is safe anyway. If
> > you want this feature please raise an issue, otherwise in the meantime
> > you can use HQL for your example:
> >
> > repos = Repo.findAll("from Repo where name like '%?%'", ["SnipSnap"])
> >
> > Cheers
> > Graeme
> >
> > On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> >> Hmm. This does not find any Books.
> >>
> >> repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find
> >> any Repos, but
> >>
> >> SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the repo.
> >>
> >> Any ideas?
> >>
> >> bye
> >> -stephan
> >>
> >>> Hi Stephan,
> >>>
> >>> Yes there is it takes a groovy list:
> >>>
> >>> results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
> >>>
> >>> Cheers
> >>> Graeme
> >>>
> >>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> >>>> Hello,
> >>>>
> >>>> how do I pass parameters to findAllByLike in a safe way?
> >>>>
> >>>> results = Book.findAllByTitleLike("%Hobbit%")
> >>>>
> >>>> Is there a
> >>>>
> >>>> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
> >>>>
> >>>> bye
> >>>> -stephan
> >>>>
> >>
> >>
>
> --
>    Stephan Schmidt
>    [hidden email]
>
>    PRESS ON. Nothing in the world can take the place of persistence.
>    Talent will not; nothing in the world is more common than
> unsuccessful
>    men with talent. Genius will not; unrewarded genius is almost a
> proverb.
>    Education will not; the world is full of educated derelicts.
> Persistence
>    and determination alone are omnipotent. - Calvin Coolidge
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

graemer
Stephan,

Can you try this against CVS head there was a bug in the find method
but it wasn't related to this I've added additional unit tests but
can't reproduce the problem.

Try this query instead:

def repos = Repo.findAll("from Repo where name like ?", [ "%Pool%" ])

ie without the quotes and the % signs in the query param

Cheers
Graeme

On 3/24/06, Graeme Rocher <[hidden email]> wrote:

> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> > def repos = Repo.findAll("from Repo where name like '%?%' ", [ "Pool" ])
> >
> > This creates:
> >
> > Message: java.lang.IndexOutOfBoundsException: Remember that ordinal
> > parameters are 1-based!
> > Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal
> > parameters are 1-based!
> Woopss :-) Can you raise an issue please!
>
> Graeme
>
> >
> > bye
> > -stephan
> >
> >
> > > Ah sorry i was talking rubbish. This is not supported in dynamic
> > > method expressions at the moment and is not really necessary as
> > > internally it uses the Hibernate Criteria API, so is safe anyway. If
> > > you want this feature please raise an issue, otherwise in the meantime
> > > you can use HQL for your example:
> > >
> > > repos = Repo.findAll("from Repo where name like '%?%'", ["SnipSnap"])
> > >
> > > Cheers
> > > Graeme
> > >
> > > On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> > >> Hmm. This does not find any Books.
> > >>
> > >> repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find
> > >> any Repos, but
> > >>
> > >> SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the repo.
> > >>
> > >> Any ideas?
> > >>
> > >> bye
> > >> -stephan
> > >>
> > >>> Hi Stephan,
> > >>>
> > >>> Yes there is it takes a groovy list:
> > >>>
> > >>> results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
> > >>>
> > >>> Cheers
> > >>> Graeme
> > >>>
> > >>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
> > >>>> Hello,
> > >>>>
> > >>>> how do I pass parameters to findAllByLike in a safe way?
> > >>>>
> > >>>> results = Book.findAllByTitleLike("%Hobbit%")
> > >>>>
> > >>>> Is there a
> > >>>>
> > >>>> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
> > >>>>
> > >>>> bye
> > >>>> -stephan
> > >>>>
> > >>
> > >>
> >
> > --
> >    Stephan Schmidt
> >    [hidden email]
> >
> >    PRESS ON. Nothing in the world can take the place of persistence.
> >    Talent will not; nothing in the world is more common than
> > unsuccessful
> >    men with talent. Genius will not; unrewarded genius is almost a
> > proverb.
> >    Education will not; the world is full of educated derelicts.
> > Persistence
> >    and determination alone are omnipotent. - Calvin Coolidge
> >
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: findAllBy with params?

Stephan.Schmidt
Ok, I'll try,

currently I use

      return Repo.list().findAll { repo -> repo.name.toLowerCase
().contains(name) }

which should work fine for the small amount of data I have
and I'm more in control :-)

bye
-stephan

> Stephan,
>
> Can you try this against CVS head there was a bug in the find method
> but it wasn't related to this I've added additional unit tests but
> can't reproduce the problem.
>
> Try this query instead:
>
> def repos = Repo.findAll("from Repo where name like ?", [ "%Pool%" ])
>
> ie without the quotes and the % signs in the query param
>
> Cheers
> Graeme
>
> On 3/24/06, Graeme Rocher <[hidden email]> wrote:
>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>>> def repos = Repo.findAll("from Repo where name like '%?%' ",  
>>> [ "Pool" ])
>>>
>>> This creates:
>>>
>>> Message: java.lang.IndexOutOfBoundsException: Remember that ordinal
>>> parameters are 1-based!
>>> Caused by: java.lang.IndexOutOfBoundsException: Remember that  
>>> ordinal
>>> parameters are 1-based!
>> Woopss :-) Can you raise an issue please!
>>
>> Graeme
>>
>>>
>>> bye
>>> -stephan
>>>
>>>
>>>> Ah sorry i was talking rubbish. This is not supported in dynamic
>>>> method expressions at the moment and is not really necessary as
>>>> internally it uses the Hibernate Criteria API, so is safe  
>>>> anyway. If
>>>> you want this feature please raise an issue, otherwise in the  
>>>> meantime
>>>> you can use HQL for your example:
>>>>
>>>> repos = Repo.findAll("from Repo where name like '%?%'",  
>>>> ["SnipSnap"])
>>>>
>>>> Cheers
>>>> Graeme
>>>>
>>>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>>>>> Hmm. This does not find any Books.
>>>>>
>>>>> repos = Repo.findAllByNameLike("%?%" , ["SnipSnap"]) does not find
>>>>> any Repos, but
>>>>>
>>>>> SELECT * ...  LIKE "%SnipSnap%" in a mysql tool does find the  
>>>>> repo.
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> bye
>>>>> -stephan
>>>>>
>>>>>> Hi Stephan,
>>>>>>
>>>>>> Yes there is it takes a groovy list:
>>>>>>
>>>>>> results = Book.findAllByTitleLike("%?%", [ "Hobbit"] )
>>>>>>
>>>>>> Cheers
>>>>>> Graeme
>>>>>>
>>>>>> On 3/24/06, Stephan J. Schmidt <[hidden email]> wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> how do I pass parameters to findAllByLike in a safe way?
>>>>>>>
>>>>>>> results = Book.findAllByTitleLike("%Hobbit%")
>>>>>>>
>>>>>>> Is there a
>>>>>>>
>>>>>>> results = Book.findAllByTitleLike("%?%", "Hobbit") ?
>>>>>>>
>>>>>>> bye
>>>>>>> -stephan
>>>>>>>
>>>>>
>>>>>
>>>
>>> --
>>>    Stephan Schmidt
>>>    [hidden email]
>>>
>>>    PRESS ON. Nothing in the world can take the place of persistence.
>>>    Talent will not; nothing in the world is more common than
>>> unsuccessful
>>>    men with talent. Genius will not; unrewarded genius is almost a
>>> proverb.
>>>    Education will not; the world is full of educated derelicts.
>>> Persistence
>>>    and determination alone are omnipotent. - Calvin Coolidge
>>>
>>>
>>>
>>

--
   Stephan Schmidt
   [hidden email]

   PRESS ON. Nothing in the world can take the place of persistence.
   Talent will not; nothing in the world is more common than  
unsuccessful
   men with talent. Genius will not; unrewarded genius is almost a  
proverb.
   Education will not; the world is full of educated derelicts.  
Persistence
   and determination alone are omnipotent. - Calvin Coolidge