Skip to content

Commit

Permalink
Fix dbQuoteLiteral() for zero-length dates and times
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Apr 29, 2024
1 parent 50c5933 commit 05c7171
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions R/dbQuoteLiteral__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ dbQuoteLiteral__duckdb_connection <- function(conn, x, ...) {
}

if (inherits(x, "POSIXt")) {
if (length(x) == 0) {
return(SQL(character()))
}

out <- dbQuoteString(
conn,
strftime(as.POSIXct(x), "%Y-%m-%d %H:%M:%S", tz = "UTC")
Expand All @@ -26,11 +30,19 @@ dbQuoteLiteral__duckdb_connection <- function(conn, x, ...) {
}

if (inherits(x, "Date")) {
if (length(x) == 0) {
return(SQL(character()))
}

out <- callNextMethod()
return(SQL(paste0(out, "::date")))
}

if (inherits(x, "difftime")) {
if (length(x) == 0) {
return(SQL(character()))
}

out <- callNextMethod()
return(SQL(paste0(out, "::time")))
}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/helper-DBItest.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (rlang::is_installed("DBItest")) DBItest::make_context(
# dblog::dblog(drv),
list(debug = FALSE),
tweaks = DBItest::tweaks(
dbitest_version = "1.8.1",
omit_blob_tests = FALSE,
temporary_tables = FALSE,
placeholder_pattern = "?",
Expand Down

0 comments on commit 05c7171

Please sign in to comment.