Skip to content

Commit

Permalink
Revert "Merge pull request #471 from r-dbi/b-404-quote-double"
Browse files Browse the repository at this point in the history
This reverts commit 9d2e604, reversing
changes made to cb5235a.
  • Loading branch information
krlmlr committed Jun 2, 2024
1 parent a7acb1b commit 915451d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

## Bug fixes

- `dbQuoteLiteral()` uses exponential notation for numeric values (#404, #471).
- `dbQuoteLiteral()` uses the format `"%Y-%m-%d %H-%M-%S%z"` which is understood by more databases (#467, #474).

## Documentation
Expand Down
8 changes: 1 addition & 7 deletions R/dbQuoteLiteral_DBIConnection.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,8 @@ 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.integer(x)
x <- as.numeric(x)
}

x <- as.character(x)
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-interpolate.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
test_that("parameter names matched", {
expect_equal(
sqlInterpolate(ANSI(), "?a ?b", a = 1L, b = 2L),
sqlInterpolate(ANSI(), "?a ?b", a = 1, b = 2),
SQL("1 2")
)

expect_equal(
sqlInterpolate(ANSI(), "?a ?b", b = 2L, a = 1L),
sqlInterpolate(ANSI(), "?a ?b", b = 2, a = 1),
SQL("1 2")
)

expect_equal(
sqlInterpolate(ANSI(), "?a ?b", b = 2L, .dots = list(a = 1L)),
sqlInterpolate(ANSI(), "?a ?b", b = 2, .dots = list(a = 1)),
SQL("1 2")
)

expect_equal(
sqlInterpolate(ANSI(), "?a ?b", .dots = list(a = 1L, b = 2L)),
sqlInterpolate(ANSI(), "?a ?b", .dots = list(a = 1, b = 2)),
SQL("1 2")
)
})
Expand All @@ -29,21 +29,21 @@ test_that("parameters in strings are ignored", {

test_that("named parameters check matches", {
expect_error(
sqlInterpolate(ANSI(), "?a ?b", a = 1L, d = 2L),
sqlInterpolate(ANSI(), "?a ?b", a = 1, d = 2),
"Supplied values don't match named vars to interpolate"
)
})

test_that("positional parameters work", {
expect_equal(
sqlInterpolate(ANSI(), "a ? c ? d ", 1L, 2L),
sqlInterpolate(ANSI(), "a ? c ? d ", 1, 2),
SQL("a 1 c 2 d ")
)
})

test_that("positional parameters can't have names", {
expect_error(
sqlInterpolate(ANSI(), "? ?", a = 1L, 2),
sqlInterpolate(ANSI(), "? ?", a = 1, 2),
"Positional variables don't take named arguments"
)
})
Expand Down Expand Up @@ -78,7 +78,7 @@ test_that("some more complex case works as well", {

test_that("escaping quotes with doubling works", {
expect_equal(
sqlInterpolate(ANSI(), "'this is a single '' one ?quoted string' ?bar ", bar = 42L),
sqlInterpolate(ANSI(), "'this is a single '' one ?quoted string' ?bar ", bar = 42),
SQL("'this is a single '' one ?quoted string' 42 ")
)
})
Expand All @@ -93,7 +93,7 @@ test_that("corner cases work", {
"Supplied values don't match positional vars to interpolate"
)
expect_equal(
sqlInterpolate(ANSI(), "?a", a = 1L),
sqlInterpolate(ANSI(), "?a", a = 1),
SQL("1")
)
expect_equal(
Expand All @@ -105,7 +105,7 @@ test_that("corner cases work", {
"Unterminated literal"
)
expect_equal(
sqlInterpolate(ANSI(), "?a\"\"?b", a = 1L, b = 2L),
sqlInterpolate(ANSI(), "?a\"\"?b", a = 1, b = 2),
SQL("1\"\"2")
)
expect_equal(
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.00000000000000000e+00", "NULL")))
expect_equal(sql_df$x, SQL(c("1", "NULL")))
expect_equal(sql_df$y, SQL(c("'a'", "NULL")))
})

0 comments on commit 915451d

Please sign in to comment.