diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-09-24 16:55:01 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-09-24 16:55:01 +0100 |
commit | 7b1973354faf76428e490d64f323fcfcaa5f154e (patch) | |
tree | ea800980bcee3d30cfbe5015df8b4db4b43e79f4 /lib/extensions.py | |
parent | 59151886a02db66b91ed251a937d583a4c6a77b5 (diff) | |
download | psycopg2-7b1973354faf76428e490d64f323fcfcaa5f154e.tar.gz |
Fixed SQL_IN when getquoted() is called without prepare()
Diffstat (limited to 'lib/extensions.py')
-rw-r--r-- | lib/extensions.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/extensions.py b/lib/extensions.py index bb8e3dd..bdcfdf2 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -116,20 +116,21 @@ def register_adapter(typ, 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 + self._conn = None 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) + if self._conn is not None: + for obj in pobjs: + if hasattr(obj, 'prepare'): + obj.prepare(self._conn) qobjs = [o.getquoted() for o in pobjs] return b('(') + b(', ').join(qobjs) + b(')') |