Skip to content

Commit 7511325

Browse files
Merge pull request julien-duponchelle#45 from phoenixluo/master
fix new decimal parsing problem
2 parents 68fe6c7 + 3fa681c commit 7511325

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pymysqlreplication/row_event.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,18 @@ def __read_new_decimal(self, column):
320320

321321
for i in range(0, uncomp_integral):
322322
value = struct.unpack('>i', self.packet.read(4))[0] ^ mask
323-
res += str(value)
323+
res += '%09d' % value
324324

325325
res += "."
326326

327327
for i in range(0, uncomp_fractional):
328328
value = struct.unpack('>i', self.packet.read(4))[0] ^ mask
329-
res += str(value)
329+
res += '%09d' % value
330330

331331
size = compressed_bytes[comp_fractional]
332332
if size > 0:
333333
value = self.packet.read_int_be_by_size(size) ^ mask
334-
res += str(value)
334+
res += '%0*d' % (comp_fractional, value)
335335

336336
return decimal.Decimal(res)
337337

pymysqlreplication/tests/test_data_type.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def test_decimal_long_values(self):
5858
event = self.create_and_insert_value(create_query, insert_query)
5959
self.assertEqual(event.rows[0]["values"]["test"], Decimal("42000.123456"))
6060

61+
def test_decimal_long_values_1(self):
62+
create_query = "CREATE TABLE test (\
63+
test DECIMAL(20,10) \
64+
)"
65+
insert_query = "INSERT INTO test VALUES(9000000123.123456)"
66+
event = self.create_and_insert_value(create_query, insert_query)
67+
self.assertEqual(event.rows[0]["values"]["test"], Decimal("9000000123.123456"))
68+
69+
def test_decimal_long_values_2(self):
70+
create_query = "CREATE TABLE test (\
71+
test DECIMAL(20,10) \
72+
)"
73+
insert_query = "INSERT INTO test VALUES(9000000123.0000012345)"
74+
event = self.create_and_insert_value(create_query, insert_query)
75+
self.assertEqual(event.rows[0]["values"]["test"],
76+
Decimal("9000000123.0000012345"))
77+
6178
def test_decimal_negative_values(self):
6279
create_query = "CREATE TABLE test (\
6380
test DECIMAL(20,10) \

0 commit comments

Comments
 (0)