-
Notifications
You must be signed in to change notification settings - Fork 107
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
Query timeout option (SQL_ATTR_QUERY_TIMEOUT) #515
Comments
https://nanodbc.github.io/nanodbc/api.html Shouldn't be to hard to implement... The implementation in https://github.com/r-dbi/odbc/blob/main/src/odbc_result.cpp does not pass a timeout
@Odraio Currently there is no query timeout (= run forever?). What is the intended purpose of the timeout (stop long running queries?) |
@aryoda Thank you for your quick reply! It is indeed the purpose of having a query timeout to stop long running queries (or stored procedures). I did have a look at the source code of the odbc package and the nanodbc API to understand the current timeout implementation. In addition, I made my best effort to create a separate branch which contains the (concept) implementation of a query_timeout option. Could you please have a look at the branch? I would really appreciate it: main...Odraio:odbc:feature/query_timeout (I'm still unsure about passing the query_timeout from dbGetQuery to nanodbc. This may be incomplete If something is wrong or incomplete, could you please send me a message and/or modify the branch? |
@Odraio Wow, I love this strong commitment to open source (not just asking but actively contributing :-) Please give me some time (I have multiple open roadworks at the moment and want to avoid bigger context switches) |
@aryoda, @detule, @jimhester I've checked and tested the changes multiple times, but the next line of code doesn't seem to use the I was wondering if you'd like to take a look at the described line of code.
|
From a first look I'd guess that for a prepared statement not only the "prepare" statement needs a query timeout (looks like it already has in the above code) but also the actual execution of the query with
|
@aryoda I'm not sure which execute() function is called of nanodbc: L3505 - result execute(connection& conn, const string_type& query, long batch_operations, long timeout) (Is the timeout parameter missing on L3517?) I've tried calling a specific method, but the query_timeout doesn't seem to have any effect:
|
I mean the line 51 in this code: Your links show nanodbc files which shouldn't be modified. But I just saw that prepared statements do not have a query timeout argument in nanodbc's https://nanodbc.github.io/nanodbc/api.html#_CPPv4N7nanodbc7executeER9statementl So perhaps setting the query timeout in https://nanodbc.github.io/nanodbc/api.html#_CPPv4N7nanodbc7prepareER9statementRK6stringl Edit: You could also try to set the query timeout explicitly after preparing a statement by calling the PS: Without cloning, building and debugging it is difficult to say for me what exactly is missing ;-) |
@aryoda Thanks for pointing me in the right direction, I've managed to create a working solution! 😃 |
I have done some testing with your published query_timeout feature branch and the query timeout does already work partially but I cannot fetch any data from the DB. I am using MS SQL Server on Window. Can you fetch the result set of a I also cannot see the I think inheritance from the Here is my testing code together with relevant stack traces:
|
Thank you for reviewing/ testing the branch. I've executed the same tests, but all succeeded (using MS SQL Server). Test code:
Print results:
|
@Odraio Could be a build or infrastructure problem on my test system. I will check my infrastructure/setup and try it again with CRAN |
@aryoda I've created a new branch which contains the query_timeout option, updated documentation (README) and (SQLServer) tests: feature/query_timeout_option |
@Odraio I have tested your newest feature branch on a DEV DB based on a real-life PRD system and our unit tests did succeed! odbc version is 1.3.3.9000 I have also found the problem why my manual tests (reported four comments above) did not work: I have queried tables that contain at least one This is a known bug in the Now also all my manual tests succeed (= do apply the new timeout argument)! Really great work! PS: I did not check the DBI tests due to lack of time and since this will be done anyhow when you open a PR. |
@aryoda There seems to be one issue while using the query_timeout and params. -> Update 1: Perhaps something is missing in odbc_result.cpp -> |
A new fix has been pushed which resolves the issue of a query using params and query_timeout. Additional tests have been added as well. |
Issue Description and Expected Result
Previously the RODBCext package provided an option to set the query timeout. As of 2020 the package is deprecated and the better alternative is odbc (cran).
This odbc package doesn't seem to provide the described option. I was wondering if there is another way around to implement a query timeout while using odbc (perhaps something like the C code of the RODBCext package which sets the value of SQL_ATTR_QUERY_TIMEOUT).
(R does have a withTimeout function, but I want to have a reliable/ correct implementation)
The nanodbc.cpp file does have a timeout function which sets the required SQL_ATTR_QUERY_TIMEOUT attribute, but this doesn't seem to be available in the R code?
Database
Microsoft SQL Server
Reproducible Example
con <- dbConnect(
odbc::odbc(),
driver = "SQL Server",
server = "SERVERNAME",
trusted_connection = TRUE,
timeout = 5,
encoding = "Latin1")
samplequery <- dbGetQuery(con, "
SELECT * FROM [Something]
")
The text was updated successfully, but these errors were encountered: