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

fix: remove single quotes in SQL statement #45

Merged
merged 2 commits into from
May 30, 2023

Conversation

leungi
Copy link
Contributor

@leungi leungi commented May 30, 2023

Issue

With reference to the code chuck below, the single quotes around table variable generates incorrect SQL syntax for connection of type Microsoft SQL Server.

con <- DBI::dbConnect(
    odbc::odbc(),
    Driver   = my_driver,
    Server   = my_server,
    Database = my_database,
    Port     = my_port,
    Trusted_Connection = "Yes"
  )

class(con)
#> [1] "Microsoft SQL Server"
#> attr(,"package")
#> [1] ".GlobalEnv"

get_partitions(con, "my_table", "my_column")
#> Error: nanodbc/nanodbc.cpp:1617: 42000: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'my_table'.  [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. 
<SQL> 'SELECT distinct(my_column) FROM 'my_table''

Reference Code Chunk

DBI::dbGetQuery(conn, glue::glue("SELECT distinct({`column`}) FROM '{`table`}'", .con = conn))[,1]
,

Fix syntax error for Microsoft SQL Server connection type.
@ddotta
Copy link
Owner

ddotta commented May 30, 2023

Thanks @leungi for this PR!
It's ok for me. @nbc what about you?

@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4523002) 99.72% compared to head (4d611bc) 99.72%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #45   +/-   ##
=======================================
  Coverage   99.72%   99.72%           
=======================================
  Files          16       16           
  Lines         361      361           
=======================================
  Hits          360      360           
  Misses          1        1           
Impacted Files Coverage Δ
R/get_partitions.R 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ddotta ddotta merged commit 357c006 into ddotta:main May 30, 2023
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.

2 participants