Skip site navigation (1) Skip section navigation (2)

Re: Change in datetime type casting

From: Federico Di Gregorio <fog(at)dndg(dot)it>
To: psycopg(at)postgresql(dot)org
Subject: Re: Change in datetime type casting
Date: 2012-06-29 14:59:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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
> and 
> The following change in 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 Di Gregorio                         federico(dot)digregorio(at)dndg(dot)it
Studio Associato Di Nunzio e Di Gregorio        
   I filosofi son come i sociologi: il mondo non lo capiscono. -- A.R.M.

In response to


psycopg by date

Next:From: Adrian KlaverDate: 2012-06-29 15:06:52
Subject: Re: Change in datetime type casting
Previous:From: Karsten HilbertDate: 2012-06-29 14:59:16
Subject: Re: Change in datetime type casting

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group