Skip to content

Commit 6b66753

Browse files
butsonmadscientist
authored andcommitted
Support a <null> type column
A TypeObject is needed instead of returning None, as None is used to verify that the type returned is in the TYPEMAP. E.g., cursor.execute('select NULL from DUAL') fails without this change, as well as situations where a user might explicitly return NULL in place of an actual value. Add a test.
1 parent cdd32ab commit 6b66753

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)