Psycgop1 vs Psycopg2

Lists: psycopg
From: Richard Harley <raharley0(at)googlemail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Psycgop1 vs Psycopg2
Date: 2011-01-13 17:37:12
Message-ID: 4D2F3848.3050409@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: psycopg

Hello all

I've noticed Psycopg2 handles escaping backslashes differently to
Psycopg1. Currently we use psycopg1 in a large school registration
system which uses a lot of these (think AM / PM \). I think the DA is
sending them though to postgres as \\. But psycopg2 is escaping the next
character - ('a','b','c','/<----) causing issues. On one hand I want to
upgrade to psycopg2 because I know 1 is getting on a bit now...but it
works for the job. Do I need to be overly concerned about how old
Psycopg1 is now? Is upgrading to 2 going to be worth the headache?

Thanks
Richard


From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Richard Harley <raharley0(at)googlemail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Psycgop1 vs Psycopg2
Date: 2011-01-13 18:15:54
Message-ID: AANLkTinwnyH0BfZ1ALTipeyHiYt5mmsLb44wDqez-Wxm@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: psycopg

On Thu, Jan 13, 2011 at 5:37 PM, Richard Harley
<raharley0(at)googlemail(dot)com> wrote:
> Hello all
>
> I've noticed Psycopg2 handles escaping backslashes differently to
> Psycopg1. Currently we use psycopg1 in a large school registration
> system which uses a lot of these (think AM / PM \). I think the DA is
> sending them though to postgres as \\. But psycopg2 is escaping the next
> character - ('a','b','c','/<----) causing issues. On one hand I want to
> upgrade to psycopg2 because I know 1 is getting on a bit now...but it
> works for the job. Do I need to be overly concerned about how old
> Psycopg1 is now? Is upgrading to 2 going to be worth the headache?

Hi,

I'm not getting exactly what is the escaped character causing
problems: could you send a more detailed example? The query and
arguments you are executing, what are you expecting to receive on the
postgres side and what you are really receiving (it may be handy to
bump the PG logging level to log all the statements fora while in
order to obtain these informations). I am not really expecting the
escaped version of the query to be used for anything else but for the
database to run it, so your report surprises me.

Also, what postgres version are you using? Escaping rules are
different according to the standard_conforming_string setting and
whether your PG version supports it.

-- Daniele


From: Richard Harley <raharley0(at)googlemail(dot)com>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Psycgop1 vs Psycopg2
Date: 2011-01-14 13:58:42
Message-ID: AANLkTi==A+-jvTLaYKx_BakFvWmUyBq8aB134=9+kFHE@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: psycopg

Thanks for your reply Daniel.

The escaped characters are causing problems for instance in this query:

INSERT INTO REGISTER (studentid, code) VALUES ('5632', '\')

In psycopg1 this works perfectly. In psycopg2 the \ escapes the next
character and causes a syntax error at the postgres level. At least this is
what I think is happening.. the versions of postgres I am testing on are the
same - 8.1, and Zope above that. I am concerned that altering how postgres
escapes characters would cause problems elsewhere. Do you advise to upgrade
to psycopg2 in production environment ?
Thanks
Richard
On Thu, Jan 13, 2011 at 6:15 PM, Daniele Varrazzo <
daniele(dot)varrazzo(at)gmail(dot)com> wrote:

> On Thu, Jan 13, 2011 at 5:37 PM, Richard Harley
> <raharley0(at)googlemail(dot)com> wrote:
> > Hello all
> >
> > I've noticed Psycopg2 handles escaping backslashes differently to
> > Psycopg1. Currently we use psycopg1 in a large school registration
> > system which uses a lot of these (think AM / PM \). I think the DA is
> > sending them though to postgres as \\. But psycopg2 is escaping the next
> > character - ('a','b','c','/<----) causing issues. On one hand I want to
> > upgrade to psycopg2 because I know 1 is getting on a bit now...but it
> > works for the job. Do I need to be overly concerned about how old
> > Psycopg1 is now? Is upgrading to 2 going to be worth the headache?
>
> Hi,
>
> I'm not getting exactly what is the escaped character causing
> problems: could you send a more detailed example? The query and
> arguments you are executing, what are you expecting to receive on the
> postgres side and what you are really receiving (it may be handy to
> bump the PG logging level to log all the statements fora while in
> order to obtain these informations). I am not really expecting the
> escaped version of the query to be used for anything else but for the
> database to run it, so your report surprises me.
>
> Also, what postgres version are you using? Escaping rules are
> different according to the standard_conforming_string setting and
> whether your PG version supports it.
>
> -- Daniele
>


From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Cc: Richard Harley <raharley0(at)googlemail(dot)com>, Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Subject: Re: Psycgop1 vs Psycopg2
Date: 2011-01-14 16:27:30
Message-ID: 201101140827.30624.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: psycopg

On Friday 14 January 2011 5:58:42 am Richard Harley wrote:
> Thanks for your reply Daniel.
>
> The escaped characters are causing problems for instance in this query:
>
> INSERT INTO REGISTER (studentid, code) VALUES ('5632', '\')
>
> In psycopg1 this works perfectly. In psycopg2 the \ escapes the next
> character and causes a syntax error at the postgres level. At least this is
> what I think is happening.. the versions of postgres I am testing on are
> the same - 8.1, and Zope above that. I am concerned that altering how
> postgres escapes characters would cause problems elsewhere. Do you advise
> to upgrade to psycopg2 in production environment ?
> Thanks
> Richard
> On Thu, Jan 13, 2011 at 6:15 PM, Daniele Varrazzo <
>

Honestly this is not enough to go on. What is needed per Danieles previous post:

1) The query.
2) The arguments/parameters to the query and method used the pass them to the
query
3) What you expected to show up in the database
4) What did show up in the database if anything.
5) The status of standard_conforming_strings. In 8.1 though it was just
informational and did not actually do anything.

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com