Skip to content

Commit

Permalink
use better format for float (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Sep 21, 2019
1 parent f8c31d4 commit 18b0bcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pymysql/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ def escape_int(value, mapping=None):
return str(value)

def escape_float(value, mapping=None):
return ('%.15g' % value)
s = repr(value)
if s in ('inf', 'nan'):
raise ProgrammingError("%s can not be used with MySQL" % s)
if 'e' not in s:
s += 'e0'
return s

_escape_table = [unichr(x) for x in range(128)]
_escape_table[0] = u'\\0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_literal_int(self):
self.assertTrue("2" == self.connection.literal(2))

def test_literal_float(self):
self.assertTrue("3.1415" == self.connection.literal(3.1415))
self.assertEqual("3.1415e0", self.connection.literal(3.1415))

def test_literal_string(self):
self.assertTrue("'foo'" == self.connection.literal("foo"))

0 comments on commit 18b0bcb

Please sign in to comment.