Skip to content

Commit

Permalink
fix: dbQuoteLiteral() uses exponential notation for numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Apr 1, 2024
1 parent a23c544 commit af07890
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/dbQuoteLiteral_DBIConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ dbQuoteLiteral_DBIConnection <- function(conn, x, ...) {
return(SQL(blob_data, names = names(x)))
}

if (is.double(x)) {
out <- sprintf("%.17e", x)
out[is.na(x)] <- "NULL"
return(SQL(out, names = names(x)))
}

if (is.logical(x)) {
x <- as.numeric(x)
x <- as.integer(x)
}

x <- as.character(x)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-sql-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ test_that("NAs turn in NULLs", {
)
sql_df <- sqlData(ANSI(), df)

expect_equal(sql_df$x, SQL(c("1", "NULL")))
expect_equal(sql_df$x, SQL(c("1.00000000000000000e+00", "NULL")))
expect_equal(sql_df$y, SQL(c("'a'", "NULL")))
})

0 comments on commit af07890

Please sign in to comment.