odbc
odbc copied to clipboard
dbQuoteString() needs a method for Hive
Hive uses C-style escape for string literals, so the result of this pseudo reprex should be 'it\'s ok'
. (Sorry for not providing the actual reprex...)
# `con` is a Hive connection
DBI::dbQuoteString(con, "it's ok")
#> <SQL> 'it''s ok'
c.f.) https://cwiki.apache.org/confluence/display/Hive/Literals
To do this, is it necessary to define something like odbcQuoteString()
generic function?
You would define a dbQuoteString for Hive connections, in https://github.com/r-dbi/odbc/blob/master/R/db.R e.g.
setMethod(
"dbQuoteString", "Hive",
function(conn, x, ...) {
if (is(x, "SQL"))
return(x)
if (!is.character(x))
stop("x must be character or SQL", call. = FALSE)
x <- gsub("'", "\\'", enc2utf8(x))
if (length(x) == 0L) {
DBI::SQL(character())
}
else {
str <- paste("'", x, "'", sep = "")
str[is.na(x)] <- "NULL"
DBI::SQL(str)
}
})
If you are willing to do a PR for this and test that it is working for hive connections as expected I am happy to review it.
You would also likely need to define a dbQuoteIdentifier
method as well
Thanks! I will try.
Closed in #424.☃️