Re: RFC: Extend psycopg2.connect to accept all valid parameters?

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: psycopg(at)postgresql(dot)org
Subject: Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Date: 2011-11-17 11:18:45
Message-ID: 4EC4ED95.9070904@dndg.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 17/11/11 10:49, Daniele Varrazzo wrote:
> On Thu, Nov 17, 2011 at 8:31 AM, Federico Di Gregorio <fog(at)dndg(dot)it> wrote:
>
>> Looks good but I have a question: does automatic conversion always
>> generates a valid connection string? Do we need quoting for some of the
>> parameters?
>
> No: just find the docs of the connection string escaping rule. They
> are not implemented in psycopg, neither before the patch.
>
>> The main idea behind .connect() was to use dsn for the
>> generic case and provider keyword arguments as a utility for the most
>> common cases while the patch actually says "it's ok to use kwargs for
>> everything" and if we do that then it should work out of the box.
>>
>> But I almost always use username+password only so I don't know if some
>> parameters need special treatment.
>
> PQconnectdb says: To write an empty value, or a value containing
> spaces, surround it with single quotes, e.g., keyword = 'a value'.
> Single quotes and backslashes within the value must be escaped with a
> backslash, i.e., \' and \\.
>
> I'd rather do this in Python than in C, so at this point the patch is
> basically what I've written yesterday minus the **kwargs pass-through.
> Or, alternatively, a few hundred lines of C with dynamic memory
> allocation, tricky conversion of Python objects to byte strings and a
> couple of off-by-one errors peppered in less tested code paths...

Never said doing it in Python is wrong. In fact anything that isn't
time-critical (type conversions, etc.) at this point is OK in Python.

federico

--
Federico Di Gregorio fog(at)initd(dot)org
Io non sono romantica. La candelina sul tavolo mi vede e si spegne.
-- sisterconfusion

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-11-17 11:39:35 Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Previous Message Daniele Varrazzo 2011-11-17 09:58:23 Re: RFC: Extend psycopg2.connect to accept all valid parameters?