Comments (3)
Finally I changed query timeout using the following patch
--- pypyodbc.py.orig 2014-03-07 16:08:39.208447167 +0200
+++ pypyodbc.py 2014-03-14 22:06:55.174814529 +0200
@@ -89,6 +89,7 @@
SQL_MODE_DEFAULT = SQL_MODE_READ_WRITE = 0; SQL_MODE_READ_ONLY = 1
SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON = 0, 1
SQL_IS_UINTEGER = -5
+SQL_ATTR_QUERY_TIMEOUT = 0
SQL_ATTR_LOGIN_TIMEOUT = 103; SQL_ATTR_CONNECTION_TIMEOUT = 113
SQL_COMMIT, SQL_ROLLBACK = 0, 1
@@ -1145,7 +1146,7 @@
# The Cursor Class.
class Cursor:
- def __init__(self, conx, row_type_callable=None):
+ def __init__(self, conx, row_type_callable=None, timeout=0):
""" Initialize self.stmt_h, which is the handle of a statement
A statement is actually the basis of a python"cursor" object
"""
@@ -1170,6 +1171,11 @@
check_success(self, ret)
self._PARAM_SQL_TYPE_LIST = []
self.closed = False
+ self.timeout = timeout
+
+ # Set the cursor's attribute of "timeout" (Actully QUERY_TIMEOUT)
+ if timeout != 0:
+ ret = ODBC_API.SQLSetStmtAttr(self.stmt_h, SQL_ATTR_QUERY_TIMEOUT,
self.timeout, 0);
def prepare(self, query_string):
@@ -2514,11 +2520,11 @@
self.connected = 1
- def cursor(self, row_type_callable=None):
+ def cursor(self, row_type_callable=None, timeout=0):
#self.settimeout(self.timeout)
if not self.connected:
raise ProgrammingError('HY000','Attempt to use a closed connection.')
- cur = Cursor(self, row_type_callable=row_type_callable)
+ cur = Cursor(self, row_type_callable=row_type_callable,
timeout=timeout)
# self._cursors.append(cur)
return cur
Please consider including this patch in main version.
Regards,
Aleksey
Original comment by [email protected]
on 14 Mar 2014 at 8:09
from pypyodbc.
Above patch tested using the following script
#!/usr/bin/python
import pypyodbc
DSN="Driver=FreeTDS;TDS_Version=8.0;Server=10.0.0.9;Port=1433;Database=test;UID=
test;PWD=secret"
sql = pypyodbc.connect(DSN, timeout=10).cursor(timeout=3)
sql.execute("WAITFOR DELAY '00:00:30'");
> time ./test.py
Traceback (most recent call last):
...
pypyodbc.OperationalError: (u'HYT00', u'[HYT00] [FreeTDS][SQL Server]Timeout
expired')
real 0m3.585s
user 0m0.042s
sys 0m0.010s
Original comment by [email protected]
on 14 Mar 2014 at 8:13
from pypyodbc.
Hi! Thanks for providing the way to solve the problem. I have used what you
have suggested.
In version 1.3.2, the QUERY_TIMEOUT will be set default with the value
connection.timeout (default to 0, which means forever), this is the way how
pyodbc is doing with the query timeout and I think it's good to be compliant
with that.
Or you can set it by calling cursor.set_timeout(timeout).
CONNECTION_TIMEOUT will default be same as LOGIN_TIMEOUT utill I can think of a
more elegant way to set them.
Original comment by [email protected]
on 24 May 2014 at 3:26
- Changed state: Fixed
from pypyodbc.
Related Issues (20)
- Description attribute returns only first char of name (as byte) using Oracle ODBC & Linux HOT 2
- Trimmed varchar results.
- Column names get wonky on 64-bit system using iSeries DB2 driver HOT 3
- Oracle and Decimal_cvt issue
- IronPython 2.7 StopIteration exception raised when retrieving SQL data set
- "invalid literal" exceptions querying empty numeric fields when using LinuxODBC with FreeTDS
- use mbdtools,chinese character encoded by gb charset can't access correctly
- Passing datetime.date returns TypeError: Wrong Type HOT 2
- Mapping bigint in sqlserver 2008 into float, instead of int in python3
- Bad cursor description (mixed bytes and strings) on Ubuntu 14.04 HOT 2
- Row objects don't raise KeyError for invalid fields
- Data source name not found on linux + unixodbc + as400 iseries driver HOT 1
- Cannot access column names by attribute HOT 4
- pypyodbc doesn't support the MSSQL datetimeoffset column type.
- state = err_list[0][0] Index out of range
- UnicodeDecodeError because UTF-16 surrogate pairs are not handled HOT 1
- Enhancement: Support for lists as SQL parameters
- executemany is very slow
- Sage Line 100 Odbc connect KO HOT 1
- Not working on Windows 7 64 bit 3.4.3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pypyodbc.