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

immediate argument to dbSendQuery() #272

Merged
merged 10 commits into from
Nov 21, 2019
Merged

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Apr 15, 2019

Adds params and immediate arguments to dbSendQuery() (and, via dots, dbSendStatement(), dbGetQuery() and dbExecute()). Uses SQLExecDirect if immediate is TRUE; in this case, params are necessarily ignored.

Currently a very quick-and-dirty proof of concept, will refine when we agree on the API.

Part of r-dbi/DBI#268.

Closes #163. Closes #127.

library(DBI)

mssql_con <- function() {
  DBI::dbConnect(
    odbc::odbc(),
    Driver = "SQL Server Driver",
    ...,
    TDS_Version = 7.4,
    Port = 1433
  )
}

con <- mssql_con()

dbExecute(con, "SELECT 1 AS a INTO #test", immediate = TRUE)
#> [1] 1
dbGetQuery(con, "SELECT * FROM #test")
#>   a
#> 1 1
try(dbExecute(con, "SELECT 1 AS a INTO #test", immediate = TRUE))
#> Error in new_result(connection@ptr, statement, immediate) : 
#>   nanodbc/nanodbc.cpp:1526: 42S01: [FreeTDS][SQL Server]There is already an object named '#test' in the database.
dbGetQuery(con, "SELECT * FROM #test", immediate = TRUE)
#>   a
#> 1 1

Created on 2019-04-16 by the reprex package (v0.2.1.9000)

@krlmlr
Copy link
Member Author

krlmlr commented Apr 19, 2019

Should dbGetQuery() and dbExecute() always use the "direct" API if no parameters are given?

@jimhester
Copy link
Contributor

No, I think they should not use it unless it is requested.

@jimhester
Copy link
Contributor

Otherwise I think it looks good, thanks!

@krlmlr
Copy link
Member Author

krlmlr commented Apr 22, 2019

Thanks. I'll tweak and remove the "WIP" when ready.

@jimhester
Copy link
Contributor

Ok, just ping me when you do so I don't miss it!

Copy link
Contributor

@jimhester jimhester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting this to request changes until you have time to work on it @krlmlr

@jimhester jimhester changed the title WIP: immediate argument to dbSendQuery() immediate argument to dbSendQuery() Nov 21, 2019
@jimhester jimhester merged commit df12dc0 into r-dbi:master Nov 21, 2019
@jimhester
Copy link
Contributor

Ok I finished this off, thanks!

Thanks a million!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants