Skip to content

Commit af07890

Browse files
committed
fix: dbQuoteLiteral() uses exponential notation for numeric values
1 parent a23c544 commit af07890

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

R/dbQuoteLiteral_DBIConnection.R

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ dbQuoteLiteral_DBIConnection <- function(conn, x, ...) {
4848
return(SQL(blob_data, names = names(x)))
4949
}
5050

51+
if (is.double(x)) {
52+
out <- sprintf("%.17e", x)
53+
out[is.na(x)] <- "NULL"
54+
return(SQL(out, names = names(x)))
55+
}
56+
5157
if (is.logical(x)) {
52-
x <- as.numeric(x)
58+
x <- as.integer(x)
5359
}
5460

5561
x <- as.character(x)

tests/testthat/test-sql-df.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ test_that("NAs turn in NULLs", {
66
)
77
sql_df <- sqlData(ANSI(), df)
88

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

0 commit comments

Comments
 (0)