None/IN adaptation ported to Python 3.

This commit is contained in:
Daniele Varrazzo 2011-01-01 16:53:11 +01:00
parent 3e94375cf7
commit 88bb8eda3e
2 changed files with 9 additions and 8 deletions

View File

@ -132,10 +132,11 @@ class SQL_IN(object):
for obj in pobjs:
if hasattr(obj, 'prepare'):
obj.prepare(self._conn)
qobjs = [str(o.getquoted()) for o in pobjs]
return '(' + ', '.join(qobjs) + ')'
qobjs = [o.getquoted() for o in pobjs]
return b('(') + b(', ').join(qobjs) + b(')')
__str__ = getquoted
def __str__(self):
return str(self.getquoted())
class NoneAdapter(object):
@ -147,8 +148,8 @@ class NoneAdapter(object):
def __init__(self, obj):
pass
def getquoted(self):
return "NULL"
def getquoted(self, _null=b("NULL")):
return _null
# Add the "cleaned" version of the encodings to the key.

View File

@ -356,7 +356,7 @@ class HstoreTestCase(unittest.TestCase):
class AdaptTypeTestCase(unittest.TestCase):
def setUp(self):
self.conn = psycopg2.connect(tests.dsn)
self.conn = psycopg2.connect(dsn)
def tearDown(self):
self.conn.close()
@ -364,7 +364,7 @@ class AdaptTypeTestCase(unittest.TestCase):
def test_none_in_record(self):
curs = self.conn.cursor()
s = curs.mogrify("SELECT %s;", [(42, None)])
self.assertEqual("SELECT (42, NULL);", s)
self.assertEqual(b("SELECT (42, NULL);"), s)
curs.execute("SELECT %s;", [(42, None)])
d = curs.fetchone()[0]
self.assertEqual("(42,)", d)
@ -385,7 +385,7 @@ class AdaptTypeTestCase(unittest.TestCase):
self.assertEqual(ext.adapt(None).getquoted(), "NOPE!")
s = curs.mogrify("SELECT %s;", (None,))
self.assertEqual("SELECT NULL;", s)
self.assertEqual(b("SELECT NULL;"), s)
finally:
ext.register_adapter(type(None), orig_adapter)