pyodbc icon indicating copy to clipboard operation
pyodbc copied to clipboard

Allow us to change the cursor's timeout

Open hb2638 opened this issue 1 year ago • 2 comments

Please first make sure you have looked at:

  • Documentation: https://github.com/mkleehammer/pyodbc/wiki
  • Other issues

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

  • Python: 3.11
  • pyodbc: 4.0.39
  • OS: Windows
  • DB: SQL Server
  • driver: SQL Server ODBC Driver

Issue

The cursor's SQL_ATTR_QUERY_TIMEOUT gets applied when the cursor is instaniated and it uses whatever timeout the connection has at that time... ok. But the problem is there's no way to change this. I thought changing the connection's timeout would do it but that's not the case after looking at the source code.

I'm running stuff inside AWS lambda and I want to the timeout to be a few seconds less than the "remaining execution time". Lambda lets you run for up to 15 minutes, so I want my query time to be reflective of the remaining time.

Is there at least a workaround where I can call SQLSetStmtAttr with SQL_ATTR_QUERY_TIMEOUT on the cursor object from python?

hb2638 avatar May 11 '23 18:05 hb2638

Must you use same cursor object, or is it acceptable to recreate it?

v-chojas avatar May 11 '23 18:05 v-chojas

I think I can get away with recreating.

hb2638 avatar May 11 '23 18:05 hb2638