I’m using R with RMySQL library to connect to Mysql database.
I have seen there is a problem with their escaping function:
> dbEscapeStrings(con, "HE''LLO")
[1] "HE\\'\\'LLO"
this is wrong, It should be: "He\'\'LLO"
Do I have to use another function to escape quotes and double quotes?
I think you are mistaking the printed R representation with the actual result from
dbEscapeStrings(). In R\also needs to be escaped. So if you want a literal\, you need two of them\\. This is how the escaped string is displayed by R when printing and explains the observed behaviour:However, note that this is just the way that escaped string is represented within R at the console. If we
cat()orwriteLines()the escaped string to the console, instead ofprint()-ingwe see that it has been properly escaped. The latter is how MySQL would see it.