[Python-modules-commits] [python-vertica] 01/03: Import python-vertica_0.6.8.orig.tar.gz
Jean Baptiste Favre
jbfavre-guest at moszumanska.debian.org
Sun Oct 9 20:41:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
jbfavre-guest pushed a commit to branch master
in repository python-vertica.
commit 9058172d19195ba5de74a6ad69d64d07c2629682
Author: Jean Baptiste Favre <github at jbfavre.org>
Date: Sun Oct 9 16:58:13 2016 +0200
Import python-vertica_0.6.8.orig.tar.gz
---
setup.py | 2 +-
vertica_python/__init__.py | 2 +-
vertica_python/tests/date_tests.py | 4 ++--
vertica_python/tests/unicode_tests.py | 35 +++++++++++++++++++++++++++++------
vertica_python/vertica/column.py | 2 +-
vertica_python/vertica/cursor.py | 22 ++++++++++++++++------
6 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/setup.py b/setup.py
index 9e22074..233e874 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ opts = ReqOpts(None, 'git')
# version should use the format 'x.x.x' (instead of 'vx.x.x')
setup(
name='vertica-python',
- version='0.6.7',
+ version='0.6.8',
description='A native Python client for the Vertica database.',
author='Justin Berka, Alex Kim',
author_email='justin.berka at gmail.com, alex.kim at uber.com',
diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py
index e01c064..d805ea7 100644
--- a/vertica_python/__init__.py
+++ b/vertica_python/__init__.py
@@ -6,7 +6,7 @@ from vertica_python.vertica.connection import Connection
# Main module for this library.
# The version number of this library.
-version_info = (0, 6, 7)
+version_info = (0, 6, 8)
__version__ = '.'.join(map(str, version_info))
diff --git a/vertica_python/tests/date_tests.py b/vertica_python/tests/date_tests.py
index 2b69ed8..763fec0 100644
--- a/vertica_python/tests/date_tests.py
+++ b/vertica_python/tests/date_tests.py
@@ -64,10 +64,10 @@ class TimestampParsingTestCase(VerticaTestCase):
test_timestamp = '44841-05-05 22:07:58'.encode(encoding='utf-8', errors='strict')
parsed_timestamp = timestamp_parse(test_timestamp)
# Assert year was truncated properly
- self.assertEqual(datetime(year=4841, month=5, day=5, hour=22, minute=7, second=58), parsed_timestamp)
+ self.assertEqual(datetime(year=9999, month=5, day=5, hour=22, minute=7, second=58), parsed_timestamp)
def test_timestamp_with_year_over_9999_and_ms(self):
test_timestamp = '124841-05-05 22:07:58.000003'.encode(encoding='utf-8', errors='strict')
parsed_timestamp = timestamp_parse(test_timestamp)
# Assert year was truncated properly
- self.assertEqual(datetime(year=4841, month=5, day=5, hour=22, minute=7, second=58, microsecond=3), parsed_timestamp)
+ self.assertEqual(datetime(year=9999, month=5, day=5, hour=22, minute=7, second=58, microsecond=3), parsed_timestamp)
diff --git a/vertica_python/tests/unicode_tests.py b/vertica_python/tests/unicode_tests.py
index 2cfaebb..d85f49c 100644
--- a/vertica_python/tests/unicode_tests.py
+++ b/vertica_python/tests/unicode_tests.py
@@ -15,17 +15,41 @@ class UnicodeTestCase(VerticaTestCase):
assert res[0] == value
# this test is broken on python3: see issue #112
+ def test_unicode_list_parameter(self):
+ v1 = u'\u00f1'
+ v2 = 'foo'
+ v3 = 3
+ query = u"SELECT %s, %s, %s"
+
+ with connect(**conn_info) as conn:
+ cur = conn.cursor()
+ cur.execute(query, (v1, v2, v3))
+ res = cur.fetchone()
+
+ assert res[0] == v1
+ assert res[1] == v2
+ assert res[2] == v3
+
+ # this test is broken on python3: see issue #112
def test_unicode_named_parameter_binding(self):
- key = u'\u16a0'
- value = u'\u16b1'
- query = u"SELECT :{}".format(key)
+ k1 = u'\u16a0'
+ k2 = 'foo'
+ k3 = 3
+
+ v1 = u'\u16b1'
+ v2 = 'foo'
+ v3 = 3
+
+ query = u"SELECT :{}, :{}, :{}".format(k1, k2, k3)
with connect(**conn_info) as conn:
cur = conn.cursor()
- cur.execute(query, {key: value})
+ cur.execute(query, {k1: v1, k2: v2, k3: v3})
res = cur.fetchone()
- assert res[0] == value
+ assert res[0] == v1
+ assert res[1] == v2
+ assert res[2] == v3
def test_string_query(self):
value = u'test'
@@ -38,7 +62,6 @@ class UnicodeTestCase(VerticaTestCase):
assert res[0] == value
- # this test is broken on python3: see issue #112
def test_string_named_parameter_binding(self):
key = u'test'
value = u'value'
diff --git a/vertica_python/vertica/column.py b/vertica_python/vertica/column.py
index 58d0dc8..50d787e 100644
--- a/vertica_python/vertica/column.py
+++ b/vertica_python/vertica/column.py
@@ -43,7 +43,7 @@ def timestamp_parse(s):
if year_match:
year = year_match.groups()[0]
dt = _timestamp_parse_without_year(s[len(year) + 1:])
- dt = dt.replace(year=int(year) % 10000)
+ dt = dt.replace(year=min(int(year), 9999))
else:
raise errors.DataError('Timestamp value not supported: %s' % s)
diff --git a/vertica_python/vertica/cursor.py b/vertica_python/vertica/cursor.py
index 6d786d2..5cb15d0 100644
--- a/vertica_python/vertica/cursor.py
+++ b/vertica_python/vertica/cursor.py
@@ -61,7 +61,7 @@ class Cursor(object):
for key in parameters:
param = parameters[key]
# Make sure adapt() behaves properly
- if six.PY2:
+ if self.is_stringy(param) and six.PY2:
param = param.encode('utf8')
v = adapt(param).getquoted()
@@ -71,11 +71,12 @@ class Cursor(object):
operation = re.sub(match_str, v.decode('utf-8'), operation, flags=re.UNICODE)
elif isinstance(parameters, tuple):
tlist = []
- for p in parameters:
- if isinstance(p, str):
- tlist.append(adapt(p.encode('utf8')).getquoted())
- else:
- tlist.append(adapt(p).getquoted())
+ for param in parameters:
+ if self.is_stringy(param) and six.PY2:
+ param = param.encode('utf8')
+ v = adapt(param).getquoted()
+ tlist.append(v.decode('utf-8'))
+
operation = operation % tuple(tlist)
else:
raise errors.Error("Argument 'parameters' must be dict or tuple")
@@ -100,6 +101,15 @@ class Cursor(object):
else:
self.connection.process_message(message)
+
+ def is_stringy(self, s):
+ try:
+ # python 2 case
+ return isinstance(s, basestring)
+ except NameError:
+ # python 3 case
+ return isinstance(s, str)
+
def fetchone(self):
if isinstance(self._message, messages.DataRow):
if self.rowcount == -1:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-vertica.git
More information about the Python-modules-commits
mailing list