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

View File

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