tags:

views:

56

answers:

3

Hi,

I just realize that in my forms I couldn't save name like O'Brian (It would saved as O only and 'Brian will be truncated).

I'm using grails 1.2.2 with mysql.

is there simple ways to allow ' to be inserted into db ? rather than modify each form and put html replacement for that char ?

+2  A: 

use the escape character, \

e.g. O\'Brian

See http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html

That said, most DB abstraction layers will allow you to use parameterized queries that do this for you

Jonathan Fingland
+4  A: 

If inserting into the database is the problem, then you can use parameterized queries. This is strongly recommended anyway, since it avoids possible security risks.

Imagine if instead of entering just a quote character, the user enters "Brian'; DROP TABLE data" into your form!

Todd Owen
A: 

Grails and its database abstraction GORM should handle that for you, unless you are saving it yourself using some lower level API:s. See the documentation here.

You should not need to replace such characters yourself, so I suggest you have another look at your code and see if you can spot what might cause the problem. I hope you can find an easy solution, it shouldn't be hard with Grails :-)

wwwclaes