Skip to content

Commit 53ef0ce

Browse files
committed
Merge pull request #96 from tvincentNuoDB/master
Separated UUID and ScaledCount2
2 parents ac04ead + 2e06c04 commit 53ef0ce

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

pynuodb/cursor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, session, prepared_statement_cache_size):
5757
self.description = None
5858
self.rowcount = -1
5959
self.colcount = -1
60-
60+
self.rownumber = 0
6161
self.__query = None
6262

6363
@property
@@ -123,6 +123,7 @@ def execute(self, operation, parameters=None):
123123
# TODO: ???
124124
if self.rowcount < 0:
125125
self.rowcount = -1
126+
self.rownumber = 0
126127

127128
def _execute(self, operation):
128129
"""Handles operations without parameters."""
@@ -153,7 +154,7 @@ def fetchone(self):
153154
self._check_closed()
154155
if self._result_set is None:
155156
raise Error("Previous execute did not produce any results or no call was issued yet")
156-
157+
self.rownumber += 1
157158
return self._result_set.fetchone(self.session)
158159

159160
def fetchmany(self, size=None):
@@ -172,7 +173,6 @@ def fetchmany(self, size=None):
172173
else:
173174
fetched_rows.append(row)
174175
num_fetched_rows += 1
175-
176176
return fetched_rows
177177

178178
def fetchall(self):
@@ -186,7 +186,6 @@ def fetchall(self):
186186
break
187187
else:
188188
fetched_rows.append(row)
189-
190189
return fetched_rows
191190

192191
def nextset(self):

pynuodb/encodedsession.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ def putInt(self, value, isMessageId=False):
386386
self.__output += packed
387387
return self
388388

389+
#Does not preserve E notation
389390
def putScaledInt(self, value):
390391
"""
391392
Appends a Scaled Integer value to the message.
392393
@type value decimal.Decimal
393394
"""
395+
#Convert the decimal's notation into decimal
396+
value += 0
394397
scale = abs(value.as_tuple()[2])
395398
valueStr = toSignedByteString(int(value * decimal.Decimal(10**scale)))
396399
packed = chr(protocol.SCALEDLEN0 + len(valueStr)) + chr(scale) + valueStr
@@ -566,6 +569,7 @@ def getInt(self):
566569

567570
raise DataError('Not an integer')
568571

572+
#Does not preserve E notation
569573
def getScaledInt(self):
570574
"""Read the next Scaled Integer value off the session."""
571575
typeCode = self._getTypeCode()
@@ -675,7 +679,7 @@ def getClob(self):
675679
return self._takeBytes(strLength)
676680

677681
raise DataError('Not a clob')
678-
682+
679683
def getScaledTime(self):
680684
"""Read the next Scaled Time value off the session."""
681685
typeCode = self._getTypeCode()
@@ -718,12 +722,24 @@ def getUUID(self):
718722
if self._getTypeCode() == protocol.SCALEDCOUNT1:
719723
# before version 11
720724
pass
721-
if self._getTypeCode() == protocol.SCALEDCOUNT2:
722-
# version 11 and later
723-
pass
724725

725726
raise DataError('Not a UUID')
726727

728+
def getScaledCount2(self):
729+
""" Read a scaled and signed decimal from the session """
730+
typeCode = self._getTypeCode()
731+
if typeCode is protocol.SCALEDCOUNT2:
732+
scale = decimal.Decimal(fromByteString(self._takeBytes(1)))
733+
sign = fromSignedByteString(self._takeBytes(1))
734+
sign = 1 if sign < 0 else 0
735+
length = fromByteString(self._takeBytes(1))
736+
value = fromByteString(self._takeBytes(length))
737+
value = tuple(int(i) for i in str(abs(value)))
738+
scaledcount = decimal.Decimal((sign, value, -1 * int(scale)))
739+
return scaledcount
740+
741+
raise DataError('Not a Scaled Count 2')
742+
727743
def getValue(self):
728744
"""Determine the datatype of the next value off the session, then call the
729745
supporting function.
@@ -749,9 +765,13 @@ def getValue(self):
749765
return self.getBoolean()
750766

751767
# get uuid type
752-
elif typeCode in [protocol.UUID, protocol.SCALEDCOUNT1, protocol.SCALEDCOUNT2]:
768+
elif typeCode is [protocol.UUID, protocol.SCALEDCOUNT1]:
753769
return self.getUUID()
754-
770+
771+
# get Scaled Count 2 type
772+
elif typeCode is protocol.SCALEDCOUNT2:
773+
return self.getScaledCount2()
774+
755775
# get scaled int type
756776
elif typeCode in range(protocol.SCALEDLEN0, protocol.SCALEDLEN8 + 1):
757777
return self.getScaledInt()

tests/nuodb_basic_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def _test_decimal_fixture(self, value, precision, scale):
138138
cursor.execute("SELECT * FROM t")
139139
row = cursor.fetchone()
140140
self.assertEqual(row[0], value)
141-
self.assertEqual(str(row[0]), str(value))
142141
finally:
143142
try:
144143
cursor.execute("DROP TABLE t IF EXISTS")
@@ -172,7 +171,6 @@ def test_numeric_no_decimal(self):
172171

173172
# This test case produces at least three different defects, perhaps
174173
# more under the covers.
175-
@unittest.skip("produces data errors for e-notations")
176174
def test_enotation_decimal_large(self):
177175
numbers = (
178176
# Yields: AssertionError: '400000000.00' != '4E+8'

0 commit comments

Comments
 (0)