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

add query timeout to execute and executemany methods #88

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.1.0
current_version = 1.1.1
commit = True
tag = True

Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Changelog
=========

- Next version - unreleased
- 1.1.1 - 2017-03-21

- Don't fail on dates before 1900 on Python < 3.

Expand Down
2 changes: 1 addition & 1 deletion README_development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ Build a new release

9. Send new version and tags to github origin. ::

$ git push origin master --tags
$ git push origin master --follow-tags
20 changes: 12 additions & 8 deletions jaydebeapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# License along with JayDeBeApi. If not, see
# <http://www.gnu.org/licenses/>.

__version_info__ = (1, 1, 0)
__version_info__ = (1, 1, 1)
__version__ = ".".join(str(i) for i in __version_info__)

import datetime
Expand Down Expand Up @@ -347,7 +347,7 @@ def TimestampFromTicks(ticks):
return apply(Timestamp, time.localtime(ticks)[:6])

# DB-API 2.0 Module Interface connect constructor
def connect(jclassname, url, driver_args=None, jars=None, libs=None):
def connect(jclassname, url, driver_args=None, jars=None, libs=None, timeout=None):
"""Open a connection to a database using a JDBC driver and return
a Connection instance.

Expand Down Expand Up @@ -378,8 +378,7 @@ def connect(jclassname, url, driver_args=None, jars=None, libs=None):
libs = [ libs ]
else:
libs = []
jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
Copy link
Owner

Choose a reason for hiding this comment

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

Does the code work without this line?

return Connection(jconn, _converters)
return Connection(jconn, _converters, timeout)

# DB-API 2.0 Connection Object
class Connection(object):
Expand All @@ -395,10 +394,11 @@ class Connection(object):
DataError = DataError
NotSupportedError = NotSupportedError

def __init__(self, jconn, converters):
def __init__(self, jconn, converters, timeout=None):
self.jconn = jconn
self._closed = False
self._converters = converters
self._timeout = timeout

def close(self):
if self._closed:
Expand All @@ -419,7 +419,7 @@ def rollback(self):
_handle_sql_exception()

def cursor(self):
return Cursor(self, self._converters)
return Cursor(self, self._converters, self._timeout)

# DB-API 2.0 Cursor Object
class Cursor(object):
Expand All @@ -430,9 +430,10 @@ class Cursor(object):
_rs = None
_description = None

def __init__(self, connection, converters):
def __init__(self, connection, converters, timeout=None):
self._connection = connection
self._converters = converters
self._timeout = timeout

@property
def description(self):
Expand Down Expand Up @@ -486,9 +487,12 @@ def _close_last(self):

def _set_stmt_parms(self, prep_stmt, parameters):
for i in range(len(parameters)):
# print (i, parameters[i], type(parameters[i]))
prep_stmt.setObject(i + 1, parameters[i])

# https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#setQueryTimeout(int)
if self._timeout is not None:
prep_stmt.setQueryTimeout(int(self._timeout)) # unit: seconds
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer to have it fail fast: Put the conversion into the connect method and only pass down the integer so you don't need a conversion down here.


def execute(self, operation, parameters=None):
if self._connection._closed:
raise Error()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
setup(
#basic package data
name = 'JayDeBeApi',
version = '1.1.0',
version = '1.1.1',
author = 'Bastian Bowe',
author_email = '[email protected]',
license = 'GNU LGPL',
Expand Down