Re: Wierd "ProgrammingError" with "E" string prefix

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <[email protected]>
Eheh, it will obviously not work when calling getquoted() to cache the
result of the query. In the fixed version you can call getquoted(conn)
and it will execute the query and cache the result for later use.

> class Ident(object):
>     """Wrap a PostgreSQL identifier.
> 
>     Note that this adapter need to make an SQL SELECT to correctly
>     quote the identifier (that is then cached) so it can be a good
>     idea to pre-allocate identifiers by calling getquoted(conn)
>     before entering critical sections of code (where `conn` is a 
>     valid connection.)
>     """
>     def __init__(self, ident):
>         self.ident = ident
>         self.ident_quoted = None
>
>     def prepare(self, conn):
>         self._conn = conn
>     
>     def getquoted(self, conn):
>         if conn:
>             self.prepare(conn)
>         if not self.ident_quoted:
>             curs = self._conn.cursor()
>             curs.execute("SELECT quote_ident(%s)", (self.ident,))
>             self.ident_quoted = curs.fetchone()[0]
>         return self.ident_quoted
> 
>     def __str__(self):
>         return str(self.ident_quoted)


-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
 If we are going to teach "creation science" as an alternative to
  evolution, then we should also teach the stork theory as an
  alternative to biological reproduction.                -- Judith Hayes

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkmukU0ACgkQvcCgrgZGjevg2ACgpHMsbTl9LISC3zwqgdgVtARW
lQ0An3zR2LA99kOs/IAjjPd1MAs+2lHI
=dYRv
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.