Pregunta

I am trying to query database using GORM, when I pass '%' as value, its returning all the rows in the table. how can I escape % character?

def query="from Person as t WHERE  (firstName like :firstName)"
def v ="%"
gSearchMap[ firstName]= "%"+v+"%"
def rows = domain.findAll(query.toString(),gSearchMap,limits)
¿Fue útil?

Solución

You should check the documentation of your sql server for that syntax details.

in MySQL you would use the \ for that:

def query="from Person as t WHERE firstName like '%\\%%"

see Escaping MySQL wild cards

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top