pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Bunce <Tim.Bunce@pobox.com>
To: David Wheeler <david@wheeler.net>
Cc: Jeff Urlwin <jurlwin@bellatlantic.net>
Cc: dbi-dev@perl.org
Cc: pgsql-interfaces@postgresql.org
Subject: Re: :PgSQL: More Queestions
Date: Wed, 20 Nov 2002 14:53:01 +0000
Message-ID: <20021120145301.GY381@dansat.data-plan.com> (raw)
In-Reply-To: <289E1136-FC56-11D6-8F04-0003931A964A@wheeler.net>
References: <OEEMJFLOJPABMFADAPIKOEBIEDAA.jurlwin@bellatlantic.net>
	<289E1136-FC56-11D6-8F04-0003931A964A@wheeler.net>

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.



view thread (22+ messages)  latest in thread

Message-ID: <20021120145301.GY381@dansat.data-plan.com>
Permalink:  ../20021120145301.GY381@dansat.data-plan.com/
Also on:    postgresql.org/message-id/20021120145301.GY381@dansat.data-plan.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: Tim.Bunce@pobox.com, david@wheeler.net, jurlwin@bellatlantic.net, dbi-dev@perl.org
  Subject: Re: :PgSQL: More Queestions
  In-Reply-To: <20021120145301.GY381@dansat.data-plan.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox