Re: Change in datetime type casting - Mailing list psycopg

From Federico Di Gregorio
Subject Re: Change in datetime type casting
Date
Msg-id 4FEDC2E2.8030005@dndg.it
Whole thread Raw
In response to Re: Change in datetime type casting  (Adrian Klaver <adrian.klaver@gmail.com>)
Responses Re: Change in datetime type casting
Re: Change in datetime type casting
List psycopg
On 29/06/12 16:51, Adrian Klaver wrote:
>> If writing a date in and reading a string out is enough for your
>> application, you can easily write your own specialized hstore adapter
>> based on the code in extras.py.
> and
> The following change in extras.py solves the problem for dates and other
> non string types.:
>
> class HstoreAdapter(object):
>     """Adapt a Python dict to the hstore syntax."""
>     def __init__(self, wrapped):
>         self.wrapped = wrapped
>         for k in self.wrapped:                     <--
>             self.wrapped[k] = str(self.wrapped[k]) <--
>
> Is there a possibility it could find its way into psycopg2 proper?

Using str() is wrong: at least you should use adapt() and .getquoted()
to avoid SQL-injection attacks.

But I think that adding something like that would be fine. Daniele?

federico

--
Federico Di Gregorio                         federico.digregorio@dndg.it
Studio Associato Di Nunzio e Di Gregorio                  http://dndg.it
   I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M.

psycopg by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: Change in datetime type casting
Next
From: Adrian Klaver
Date:
Subject: Re: Change in datetime type casting