Skip to content

Commit

Permalink
Merge pull request #188 from r-dbi/f-quote-time
Browse files Browse the repository at this point in the history
- `dbQuoteLiteral()` now correctly quotes difftime values (#188).
  • Loading branch information
krlmlr committed Dec 22, 2020
2 parents 3d114d0 + a0924c8 commit a50e10b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ string_to_utf8 <- function(value) {

difftime_to_hms <- function(value) {
is_difftime <- vlapply(value, inherits, "difftime")
value[is_difftime] <- lapply(value[is_difftime], hms::as_hms)
# https://github.com/tidyverse/hms/issues/84
value[is_difftime] <- lapply(value[is_difftime], function(x) {
mode(x) <- "double"
hms::as_hms(x)
})
value
}

Expand Down
17 changes: 17 additions & 0 deletions R/quote.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,20 @@ setMethod("dbQuoteString", c("MariaDBConnection", "SQL"),
x
}
)

#' @rdname mariadb-quoting
#' @export
setMethod("dbQuoteLiteral", signature("MariaDBConnection"),
function(conn, x, ...) {
# Switchpatching to avoid ambiguous S4 dispatch, so that our method
# is used only if no alternatives are available.

if (inherits(x, "difftime")) return(cast_difftime(callNextMethod()))

callNextMethod()
}
)

cast_difftime <- function(x) {
SQL(paste0("CAST(", x, " AS time)"))
}
3 changes: 3 additions & 0 deletions man/mariadb-quoting.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a50e10b

Please sign in to comment.