Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glue_sql() collapses zero-length DBI::SQL object into DBI::SQL("NULL") #244

Merged
merged 5 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

* Unterminated backticks trigger the same error as unterminated single or double quotes (#237).

* `glue_sql()` collapses zero-length `DBI::SQL` object into `DBI::SQL("NULL")` (#244 @shrektan).

# glue 1.5.0

## Breaking changes
Expand Down
3 changes: 3 additions & 0 deletions R/sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ sql_quote_transformer <- function(connection, .na) {
if (should_collapse) {
res <- glue_collapse(res, ", ")
}
if (length(res) == 0L) {
res <- DBI::SQL("NULL")
}
return(res)
}

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("glue_sql", {
})
it('collapses values should return NULL for length zero vector', {
expect_identical(glue_sql("{var*}", .con = con, var = character()), DBI::SQL("NULL"))
expect_identical(glue_sql("{var*}", .con = con, var = DBI::SQL(character())), DBI::SQL("NULL"))
})
it("should return an SQL NULL by default for missing values", {
var <- list(NA, NA_character_, NA_real_, NA_integer_)
Expand Down