Re: Sanitize schema name

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Elliot S <yields(dot)falsehood(at)gmail(dot)com>
Cc: Federico Di Gregorio <fog(at)dndg(dot)it>, "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Sanitize schema name
Date: 2015-05-27 18:18:29
Message-ID: CA+mi_8YYNZ_GO4K5axhTvfsfjwtvAX_m68RQwNVsbDyapDVoqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Wed, May 27, 2015 at 5:32 PM, Elliot S <yields(dot)falsehood(at)gmail(dot)com> wrote:

> I've removed the call out to the psycopg quoting.

> %t formatting is also removed.

Thank you for these adjustments.

> I've added a quote_ident() to the connection object.

IMO we should have a function on psycopg2.extensions taking a
connection or cursor object and a string, like the various
extras.register_*. This method doesn't really belong to the connection
(it does require a connection to work, but that's pretty much like
everything else in libpq). It doesn't even belong to the cursor: it's
just an utility function wrapping some libpq functionality.

> I'm still working on my quote_ident branch
> https://github.com/psycopg/psycopg2/compare/master...yieldsfalsehood:quote_ident
>
> Return values are just bytestrings right now. bytestring input isn't
> accepted on python3.4 (only py3 I tested); unicode and bytestring inputs
> look ok for python2.7.

I'm not sure the trivial PyArg_ParseTuple(args, "s", &ident) is right
here: in py3 you have an utf8 encoded string: maybe good enough but
I'm not so sure. Looking at the libpq implementation it makes use of
the connection encoding. I think the right thing to do is, in case of
unicode input, encode it in the connection encoding.

The full roundtrip, IMO, should be a function that returns a string on
string input and a unicode on unicode input (with the respective
meaning of these terms in Py2 and Py3), using the connection encoding
for encoding/decoding in the latter case.

> The other PQescape* functions were mentioned earlier but I haven't touched
> them, yet.

We can take a look at them and work out which one would be useful
later, after we get this right.

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Shulgin, Oleksandr 2015-06-02 12:23:03 Streaming replication for psycopg2
Previous Message Elliot S 2015-05-27 16:32:42 Re: Sanitize schema name