Skip to content

Commit

Permalink
reopen cursor on conn.cursor()
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kim committed May 11, 2015
1 parent 1ea6923 commit f623a06
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# version should use the format 'x.x.x' (instead of 'vx.x.x')
setup(
name='vertica-python',
version='0.4.5',
version='0.4.6',
description='A native Python client for the Vertica database.',
author='Justin Berka, Alex Kim, Kenneth Tran',
author_email='[email protected], [email protected], [email protected]',
Expand Down
2 changes: 1 addition & 1 deletion vertica_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Main module for this library.

# The version number of this library.
version_info = (0, 4, 5)
version_info = (0, 4, 6)

__version__ = '.'.join(map(str, version_info))

Expand Down
23 changes: 23 additions & 0 deletions vertica_python/tests/basic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,26 @@ def test_query_errors(self):
assert 1 == len(res)
assert 1 == res[0][0]
assert 'aa' == res[0][1]

def test_cursor_close_and_reuse(self):

conn = vertica_python.connect(conn_info)
cur = conn.cursor()
init_table(cur)

# insert data
cur.execute(""" INSERT INTO vertica_python_unit_test (a, b) VALUES (2, 'bb'); commit; """)
#conn.commit()

# query
cur.execute("SELECT a, b from vertica_python_unit_test WHERE a = 2")
res = cur.fetchall()
assert 1 == len(res)

# close and reopen cursor
cur.close()
cur = conn.cursor()

cur.execute("SELECT a, b from vertica_python_unit_test")
res = cur.fetchall()
assert 1 == len(res)
4 changes: 3 additions & 1 deletion vertica_python/vertica/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ def cursor(self, cursor_type=None):
if self.closed():
raise errors.ConnectionError('Connection is closed')

if self._cursor.closed():
self._cursor._closed = False

# let user change type if they want?
self._cursor.cursor_type = cursor_type
return self._cursor


#
# Internal
#
Expand Down
1 change: 0 additions & 1 deletion vertica_python/vertica/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def setoutputsize(self, size, column=None):
#
# Non dbApi methods
#
# todo: input stream
def flush_to_query_ready(self):
# if the last message isnt empty or ReadyForQuery, read all remaining messages
if(self._message is None
Expand Down

0 comments on commit f623a06

Please sign in to comment.