Skip to content

Commit b9f36bb

Browse files
committed
In order to support a <null> type column being returned from
engine. A TypeObject is needed instead of returning None. As None is used to verify that the type returned is in the TYPEMAP. cursor.execute('select NULL from DUAL') fails without this change. There are other cases where a user might explictly return NULL in place of an actual value. Say in a view such as INFORMATION_SCHEMA.COLUMNS where we don't support DOMAIN_NAME column. The above example was added to tests/nuodb_types_test.py
1 parent cdd32ab commit b9f36bb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pynuodb/datatype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ def __cmp__(self, other):
154154
NUMBER = TypeObject(int, decimal.Decimal)
155155
DATETIME = TypeObject(Timestamp, Date, Time)
156156
ROWID = TypeObject()
157+
NULL = TypeObject(None)
157158

158-
TYPEMAP = {"<null>": None,
159+
TYPEMAP = {"<null>": NULL,
159160
"string": STRING,
160161
"char": STRING,
161162
"varchar": STRING,

tests/nuodb_types_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ def test_datetime_types(self):
112112
assert row[1] == datetime.time(5, 44, 33, 221100)
113113
assert row[2] == datetime.datetime(2000, 1, 1, 5, 44, 33, 221100)
114114
assert row[3] == datetime.datetime(2000, 1, 1, 5, 44, 33, 221100)
115+
116+
def test_null_type(self):
117+
con = self._connect()
118+
cursor = con.cursor()
119+
120+
null_type = self.driver.TypeObjectFromNuodb('<null>')
121+
122+
cursor.execute("SELECT NULL from dual")
123+
row = cursor.fetchone()
124+
125+
assert len(row) == 1
126+
assert cursor.description[0][1] == null_type
127+
assert row[0] is None

0 commit comments

Comments
 (0)