Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote difftime values #188

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.