0

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)
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
sfgroups
  • 18,151
  • 28
  • 132
  • 204
  • elaborate your question. What you are describing now is perfectly valid behavior. `select * from person where firstname like '%%%'` gives you all rows in a table which are not null. btw, `gSearchMap[ firstName]= "%"+v+"%"` this is wrong. – injecteer Mar 30 '14 at 00:47
  • I want to select only fistname column contains % character. I get the % value from user, what is the best way to escape this character? – sfgroups Mar 30 '14 at 01:46

1 Answers1

0

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

Community
  • 1
  • 1
injecteer
  • 20,038
  • 4
  • 45
  • 89