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

Dates in MS Access aren't escaped properly. #608

Closed
erikvona opened this issue Mar 8, 2021 · 0 comments · Fixed by #609
Closed

Dates in MS Access aren't escaped properly. #608

erikvona opened this issue Mar 8, 2021 · 0 comments · Fixed by #609
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL

Comments

@erikvona
Copy link
Contributor

erikvona commented Mar 8, 2021

Escaping dates when using a connection to MS Access goes wrong

Access uses octothorpes to delimit dates, and requires dates to be formatted either YYYY-MM-DD or MM/DD/YYYY. Optionally with hh:mm:ss as time, timezones are not supported.

escape(Sys.Date(), con = simulate_access())
# Expected: #2021-03-08#, or: #03/08/2021#
# Returned: '2021-03-08'
escape(Sys.time(), con = simulate_access())
# Expected: #2021-03-08 09:30:30#
# Returned: '2021-03-08T09:30:30Z'

The relevant docs are here concerning how to use dates in queries in MS Access.

To work around the issue, I currently use the following function. However, it doesn't handle collapse/parentheses, only single values.

escape_access <- function(x){
  if(inherits(x, "Date")){
    return(sql(ifelse(is.na(x), "NULL", format(x, "#%F#"))))
  }
  else if(inherits(x, "POSIXt")){
    return(sql(ifelse(is.na(x), "NULL", format(x, "#%F %T#"))))
  }else{
    escape(x, con = simulate_access())
  }
}
@hadley hadley added feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL labels Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement func trans 🌍 Translation of individual functions to SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants