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

Conversation

shrektan
Copy link
Contributor

This is a missed case of #134

The real use case that hurts in reality is :

When using Oracle database, the date object must be in format like date'yyyy-mm-dd'. Thus, we need to do:

sql_dates <- DBI::SQL(sprintf("date'%s'", dates))
glue::glue_sql("select * from table where ref_date in ({sql_dates*})", .con = con)

Thus, when dates is zero-length, sql_dates would be zero-length as well, but it leads to an empty SQL string in the current version of glue.

This PR fixes this. It results a valid SQL: select * from table where ref_date in (NULL)

@shrektan shrektan changed the title glue_sql() should collapses zero-length DBI::SQL object into DBI::SQL("NULL") glue_sql() collapses zero-length DBI::SQL object into DBI::SQL("NULL") Nov 26, 2021
@jennybc
Copy link
Member

jennybc commented Nov 29, 2021

@jimhester Do you agree this is good to go?

@jennybc jennybc merged commit a24c975 into tidyverse:main Nov 29, 2021
@shrektan shrektan deleted the zero-length-SQL-NULL branch November 29, 2021 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants