Skip to content

Commit

Permalink
Fix issue with adaptation of empty arrays in pg
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 10, 2016
1 parent f56468b commit 55c84b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/contents/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Version 5.0.1
on the mailing list by Justin Pryzby).
- Allow extra values that are not used in the command in the parameter dict
passed to the query_formatted() method (as suggested by Justin Pryzby).
- Improved handling of empty arrays in the classic module.
- Unused classic connections were not properly garbage collected which could
cause memory leaks (reported by Justin Pryzby).
- Made C extension compatible with MSVC 9 again (this was needed to compile for
Expand Down
2 changes: 1 addition & 1 deletion pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def guess_simple_type(cls, value):
if isinstance(value, (date, time, datetime, timedelta)):
return 'date'
if isinstance(value, list):
return '%s[]' % cls.guess_simple_base_type(value)
return '%s[]' % (cls.guess_simple_base_type(value) or 'text',)
if isinstance(value, tuple):
simple_type = cls.simple_type
typ = simple_type('record')
Expand Down
12 changes: 12 additions & 0 deletions tests/test_classic_dbwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,18 @@ def testQueryFormatted(self):
r = q.getresult()[0][0]
self.assertEqual(r, 'alphabetagammadeltaepsilon')

def testQueryFormattedWithAny(self):
f = self.db.query_formatted
q = "select 2 = any(%s)"
r = f(q, [[1, 3]]).getresult()[0][0]
self.assertEqual(r, False if pg.get_bool() else 'f')
r = f(q, [[1, 2, 3]]).getresult()[0][0]
self.assertEqual(r, True if pg.get_bool() else 't')
r = f(q, [[]]).getresult()[0][0]
self.assertEqual(r, False if pg.get_bool() else 'f')
r = f(q, [[None]]).getresult()[0][0]
self.assertIsNone(r)

def testPkey(self):
query = self.db.query
pkey = self.db.pkey
Expand Down

0 comments on commit 55c84b2

Please sign in to comment.