Skip to content

Commit 7949c45

Browse files
committed
Merge pull request #113 from tvincentNuoDB/master
Updated ScaledCount2 handling of negative values
2 parents f57e330 + cb00e43 commit 7949c45

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pynuodb/encodedsession.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,10 @@ def putScaledCount2(self, value):
658658
:type value: decimal.Decimal
659659
"""
660660
scale = abs(value.as_tuple()[2])
661-
sign = "1" if value.as_tuple()[0] == 0 else "-1"
662-
value = toSignedByteString(int(value * decimal.Decimal(10**scale)))
663-
packed = chr(protocol.SCALEDCOUNT2) + chr(scale) + sign + chr(len(value)) + value
661+
sign = 1 if value.as_tuple()[0] == 0 else -1
662+
sign = toSignedByteString(sign)
663+
value = toByteString(int(abs(value) * decimal.Decimal(10**scale)))
664+
packed = chr(protocol.SCALEDCOUNT2) + toByteString(scale) + sign + chr(len(value)) + value
664665
self.__output += packed
665666
return self
666667

@@ -1076,5 +1077,3 @@ def getCommitInfo(self, nodeID):
10761077
""" Currently does not support last commit """
10771078

10781079
return 0
1079-
1080-

tests/nuodb_basic_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def _test_decimal_fixture(self, value, precision, scale):
155155
#
156156
def test_many_significant_digits(self):
157157
self._test_decimal_fixture(decimal.Decimal("31943874831932418390.01"), 38, 12)
158+
self._test_decimal_fixture(decimal.Decimal("-31943874831932418390.01"), 38, 12)
158159

159160
# This test demonstrates the broken implementation of getScaledInt
160161
# which results in:

0 commit comments

Comments
 (0)