Re: :PgSQL: More Queestions

From: Tim Bunce <Tim(dot)Bunce(at)pobox(dot)com>
To: David Wheeler <david(at)wheeler(dot)net>
Cc: Jeff Urlwin <jurlwin(at)bellatlantic(dot)net>, dbi-dev(at)perl(dot)org, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: :PgSQL: More Queestions
Date: 2002-11-20 14:53:01
Message-ID: 20021120145301.GY381@dansat.data-plan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Tue, Nov 19, 2002 at 11:03:23PM -0800, David Wheeler wrote:
> On Tuesday, November 19, 2002, at 03:42 PM, Jeff Urlwin wrote:
>
> But if I change it (as I'm seriously considering, in light of
> PostgreSQL 7.3's support for prepared statements), I'll probably do no
> parsing for comments.

I think that would be a bad move.

> I understand that the goal is to convert the placeholders from '?' or
> ':nn' to the PostgreSQL internal version (':pn'). What I'm referring to
> specifically, however, is this snippet from DBD::Pg:
>
> if (in_literal) {
> /* Check if literal ends but keep quotes in literal */
> if (*src == in_literal) {
> int bs = 0;
> char *str;
> str = src-1; /* Back a character. */
> while (*(str - bs) == '\\')
> bs++;
> if (!(bs & 1))
> /* bs is an even number? */
> in_literal = 0;
> }
> *dest++ = *src++;
> continue;
> }
>
> in_literal is set when the last character wasn't a placeholder
> character ('?' or ':') and is either a single or a double quotation
> mark. So while I understand that one might want to ignore placeholder
> characters, I don't really understand what the above code is doing.

If it's seen the start of a string ("..." or '...') then it just
keeps copying the string till it finds the same type of quote
character to mark the end of the string. The 'fiddly bit in the
middle' is handling backslashes used to escape quote chars in the
middle of the string: "...\"..." and "...\\" (odd vs even number).

> Maybe it's just too complex, because, looking at DBD::ODBC's
> dbd_preparse(), the handling of literals in the query seems a good deal
> more straight-forward (though it doesn't appear to handle '\'' or "\""
> -- am I reading that right?

ANSI standard doesn't use backslashes, it uses doubling: "...""..."

Take a look at dbd_preparse in DBD::Oracle.

There's also a preparse() in DBI.xs which was destined to become a
standard service offered to drivers - but isn't quite ready yet.

Tim.

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tim Bunce 2002-11-20 15:02:13 Re: DBD::PgSQL: More Queestions
Previous Message Rudy Lippan 2002-11-20 13:58:59 Re: DBD::PgSQL: More Queestions