Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 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 @@ -379,7 +379,7 @@ def connect(jclassname, url, driver_args=None, jars=None, libs=None):
else:
libs = []
jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
return Connection(jconn, _converters)
return Connection(jconn, _converters, timeout)

# DB-API 2.0 Connection Object
class Connection(object):
Expand All @@ -395,10 +395,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 +420,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 +431,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 +488,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
Copy Markdown
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 = 'bastian.dev@gmail.com',
license = 'GNU LGPL',
Expand Down
9 changes: 9 additions & 0 deletions test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,12 @@ def test_runtime_exception_on_rollback(self):
fail("expected exception")
except jaydebeapi.InterfaceError as e:
self.assertEquals(str(e), "java.lang.RuntimeException: expected")

def test_connection_timeout(self):
driver = 'org.jaydebeapi.mockdriver.MockDriver'
url = 'jdbc:jaydebeapi://dummyurl'
conn = jaydebeapi.connect(driver, url, timeout=10)
cursor = conn.cursor()
cursor.execute("dummy stmt")
result = cursor.fetchone()
self.assertIsNotNone(result)