Skip to content

Commit

Permalink
Add a dbQuoteLiteral method for logical class (#479)
Browse files Browse the repository at this point in the history
Fixes #478
  • Loading branch information
meztez authored Nov 7, 2023
1 parent 99a396e commit 9c828cb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ exportMethods(dbIsValid)
exportMethods(dbListFields)
exportMethods(dbListTables)
exportMethods(dbQuoteIdentifier)
exportMethods(dbQuoteLiteral)
exportMethods(dbQuoteString)
exportMethods(dbReadTable)
exportMethods(dbRemoveTable)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# bigrquery (development version)

* Add a `dbQuoteLiteral()` method for logicals to revert breaking change
introduced by DBI 1.1.2 (@meztez, #478).

* bigrquery is now MIT licensed (#453).

* Deprecated functions (i.e. those not starting with `bq_`) have been
Expand Down
10 changes: 10 additions & 0 deletions R/dbi-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ setMethod(
}
)

#' @rdname DBI
#' @export
setMethod(
"dbQuoteLiteral", c("BigQueryConnection", "logical"),
function(conn, x, ...) {
x <- as.character(x)
x[is.na(x)] <- "NULL"
SQL(x, names = names(x))
}
)

#' @rdname DBI
#' @inheritParams DBI::dbDataType
Expand Down
3 changes: 3 additions & 0 deletions man/DBI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/test-dbi-connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ test_that("the return type of integer columns is set by the bigint argument", {
expect_equal(DBI::dbGetQuery(con_integer64, sql)$x, bit64::as.integer64(x))
expect_equal(DBI::dbGetQuery(con_character, sql)$x, x)
})

test_that("DBI::sqlData return TRUE, FALSE for logical class", {
con <- dbConnect(bigquery(), project = bq_test_project())
expect_equal(
DBI::dbQuoteLiteral(con, c(TRUE, FALSE, NA)),
DBI::SQL(c("TRUE", "FALSE", "NULL"))
)
})

0 comments on commit 9c828cb

Please sign in to comment.