Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9f71220

Browse filesBrowse files
sir-sigurdmethane
authored andcommitted
Fix conversion of decimals with exponent (PyMySQL#286)
1 parent 21170a7 commit 9f71220
Copy full SHA for 9f71220

File tree

Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed

‎MySQLdb/converters.py

Copy file name to clipboardExpand all lines: MySQLdb/converters.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def Thing2Literal(o, d):
8282
that method when the connection is created."""
8383
return string_literal(o, d)
8484

85+
def Decimal2Literal(o, d):
86+
return format(o, 'f')
8587

8688
def char_array(s):
8789
return array.array('c', s)
@@ -142,6 +144,6 @@ def quote_tuple(t, d):
142144
from decimal import Decimal
143145
conversions[FIELD_TYPE.DECIMAL] = Decimal
144146
conversions[FIELD_TYPE.NEWDECIMAL] = Decimal
145-
conversions[Decimal] = Thing2Str
147+
conversions[Decimal] = Decimal2Literal
146148
except ImportError:
147149
pass

‎tests/capabilities.py

Copy file name to clipboardExpand all lines: tests/capabilities.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ def generator(row,col):
202202
('col1 DECIMAL(5,2)',),
203203
generator)
204204

205+
val = Decimal('1.11111111111111119E-7')
206+
self.cursor.execute('SELECT %s', (val,))
207+
result = self.cursor.fetchone()[0]
208+
self.assertEqual(result, val)
209+
self.assertIsInstance(result, Decimal)
210+
205211
self.cursor.execute('SELECT %s + %s', (Decimal('0.1'), Decimal('0.2')))
206212
result = self.cursor.fetchone()[0]
207213
self.assertEqual(result, Decimal('0.3'))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.