mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 10:53:44 +03:00
Moved SQL_IN to extensions and away from extras.
This commit is contained in:
parent
d342d37e27
commit
e59ef4de4b
|
@ -1,5 +1,8 @@
|
||||||
2007-01-16 Federico Di Gregorio <fog@initd.org>
|
2007-01-16 Federico Di Gregorio <fog@initd.org>
|
||||||
|
|
||||||
|
* lib/extras.py: moved SQL_IN to extensions.py; we're now officially
|
||||||
|
adapting tuples.
|
||||||
|
|
||||||
* psycopg/adapt_mxdatetime.c: fixed #137 by accessing the 'date' and
|
* psycopg/adapt_mxdatetime.c: fixed #137 by accessing the 'date' and
|
||||||
'time' attributes of the mx.DateTime instance: they are always in ISO
|
'time' attributes of the mx.DateTime instance: they are always in ISO
|
||||||
format.
|
format.
|
||||||
|
|
|
@ -66,4 +66,30 @@ def register_adapter(typ, callable):
|
||||||
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
|
"""Register 'callable' as an ISQLQuote adapter for type 'typ'."""
|
||||||
adapters[(typ, ISQLQuote)] = callable
|
adapters[(typ, ISQLQuote)] = callable
|
||||||
|
|
||||||
|
|
||||||
|
# The SQL_IN class is the official adapter for tuples starting from 2.0.6.
|
||||||
|
class SQL_IN(object):
|
||||||
|
"""Adapt any iterable to an SQL quotable object."""
|
||||||
|
|
||||||
|
def __init__(self, seq):
|
||||||
|
self._seq = seq
|
||||||
|
|
||||||
|
def prepare(self, conn):
|
||||||
|
self._conn = conn
|
||||||
|
|
||||||
|
def getquoted(self):
|
||||||
|
# this is the important line: note how every object in the
|
||||||
|
# list is adapted and then how getquoted() is called on it
|
||||||
|
pobjs = [adapt(o) for o in self._seq]
|
||||||
|
for obj in pobjs:
|
||||||
|
if hasattr(obj, 'prepare'):
|
||||||
|
obj.prepare(self._conn)
|
||||||
|
qobjs = [str(o.getquoted()) for o in pobjs]
|
||||||
|
return '(' + ', '.join(qobjs) + ')'
|
||||||
|
|
||||||
|
__str__ = getquoted
|
||||||
|
|
||||||
|
register_adapter(tuple, SQL_IN)
|
||||||
|
|
||||||
|
|
||||||
__all__ = [ k for k in locals().keys() if not k.startswith('_') ]
|
__all__ = [ k for k in locals().keys() if not k.startswith('_') ]
|
||||||
|
|
|
@ -27,7 +27,6 @@ except:
|
||||||
|
|
||||||
from psycopg2.extensions import cursor as _cursor
|
from psycopg2.extensions import cursor as _cursor
|
||||||
from psycopg2.extensions import connection as _connection
|
from psycopg2.extensions import connection as _connection
|
||||||
from psycopg2.extensions import register_adapter as _RA
|
|
||||||
from psycopg2.extensions import adapt as _A
|
from psycopg2.extensions import adapt as _A
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,29 +121,6 @@ class DictRow(list):
|
||||||
for n, v in self._index.items():
|
for n, v in self._index.items():
|
||||||
yield n, list.__getitem__(self, v)
|
yield n, list.__getitem__(self, v)
|
||||||
|
|
||||||
class SQL_IN(object):
|
|
||||||
"""Adapt any iterable to an SQL quotable object."""
|
|
||||||
|
|
||||||
def __init__(self, seq):
|
|
||||||
self._seq = seq
|
|
||||||
|
|
||||||
def prepare(self, conn):
|
|
||||||
self._conn = conn
|
|
||||||
|
|
||||||
def getquoted(self):
|
|
||||||
# this is the important line: note how every object in the
|
|
||||||
# list is adapted and then how getquoted() is called on it
|
|
||||||
pobjs = [_A(o) for o in self._seq]
|
|
||||||
for obj in pobjs:
|
|
||||||
if hasattr(obj, 'prepare'):
|
|
||||||
obj.prepare(self._conn)
|
|
||||||
qobjs = [str(o.getquoted()) for o in pobjs]
|
|
||||||
return '(' + ', '.join(qobjs) + ')'
|
|
||||||
|
|
||||||
__str__ = getquoted
|
|
||||||
|
|
||||||
_RA(tuple, SQL_IN)
|
|
||||||
|
|
||||||
|
|
||||||
class LoggingConnection(_connection):
|
class LoggingConnection(_connection):
|
||||||
"""A connection that logs all queries to a file or logger object."""
|
"""A connection that logs all queries to a file or logger object."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user