Commit aafb8bc4 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Decode base64-encoded binary values from the server

parent e3a8e9e5
......@@ -14,6 +14,7 @@
import logging
import collections
import base64
from decimal import Decimal
from phoenixdb.errors import OperationalError, NotSupportedError, ProgrammingError
......@@ -134,6 +135,8 @@ class Cursor(object):
self._data_types.append((i, Decimal))
elif column['columnClassName'] == 'java.lang.Float' or column['columnClassName'] == 'java.lang.Double':
self._data_types.append((i, float))
elif column['type']['name'] == 'BINARY':
self._data_types.append((i, base64.b64decode))
def _set_frame(self, frame):
self._frame = frame
......
......@@ -130,7 +130,7 @@ class TypesTest(DatabaseTestCase):
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [[1, 'abc'], [2, None], [3, 'abc'], [4, None], [5, None], [6, None]])
@unittest.skip("broken")
@unittest.skip("https://issues.apache.org/jira/browse/CALCITE-780")
def test_varchar_very_long(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val varchar")
with self.conn.cursor() as cursor:
......@@ -184,13 +184,13 @@ class TypesTest(DatabaseTestCase):
cursor.execute("UPSERT INTO phoenixdb_test_tbl1 VALUES (4, ?)", ['\x01\x00'])
cursor.execute("SELECT id, val FROM phoenixdb_test_tbl1 ORDER BY id")
self.assertEqual(cursor.fetchall(), [
[1, 'ab'.encode('base64').strip()],
[2, 'ab'.encode('base64').strip()],
[3, '\x01\x00'.encode('base64').strip()],
[4, '\x01\x00'.encode('base64').strip()],
[1, 'ab'],
[2, 'ab'],
[3, '\x01\x00'],
[4, '\x01\x00'],
])
@unittest.skip("broken")
@unittest.skip("https://issues.apache.org/jira/browse/CALCITE-781")
def test_binary2(self):
self.createTable("phoenixdb_test_tbl1", "id integer primary key, val binary(2)")
with self.conn.cursor() as cursor:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment