I'm inserting some strings into a MYSQL table via an R script. Some of the strings include apostrophes that need to be escaped prior to inserting into the table.
Given the following string:
myStr <- "AIN'T NO ELMERS"
I have tried the following alternatives with no luck:
str_replace(horse,'(\w+)(’)(.*)','\1\\\2\3')) ==> results in an error message
str_replace(horse,'(\w+)(\’)(.*)','\1\\\2\3')) ==> no error but the inserted string is AIN’T NO ELMERS
How does one escape successfully escape the apostrophe in the string?
My r script takes the following form:
library(DBI)
library(odbc)
library(RMariaDB)
insert <- dbSendQuery(con, "INSERT ignore INTO names(`name`, `value`) VALUES (?, ?)")
dbBind(insert, names)
dbClearResult(insert)
con <- dbDisconnect(con)