Question

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)
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top