Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7AE3B475B8E for ; Wed, 20 Nov 2002 09:53:02 -0500 (EST) Received: from mail04.svc.cra.dublin.eircom.net (mail04.svc.cra.dublin.eircom.net [159.134.118.20]) by postgresql.org (Postfix) with SMTP id 9B7C5475B8A for ; Wed, 20 Nov 2002 09:53:01 -0500 (EST) Received: (qmail 2275 messnum 1307184 invoked from network[159.134.166.126/p638.as1.limerick1.eircom.net]); 20 Nov 2002 14:53:03 -0000 Received: from p638.as1.limerick1.eircom.net (HELO dansat.data-plan.com) (159.134.166.126) by mail04.svc.cra.dublin.eircom.net (qp 2275) with SMTP; 20 Nov 2002 14:53:03 -0000 Received: from dansat.data-plan.com (localhost [127.0.0.1]) by dansat.data-plan.com (8.12.6/8.12.6) with ESMTP id gAKEr7ao011574; Wed, 20 Nov 2002 14:53:07 GMT (envelope-from timbo@dansat.data-plan.com) Received: (from timbo@localhost) by dansat.data-plan.com (8.12.6/8.12.6/Submit) id gAKEr6d8011573; Wed, 20 Nov 2002 14:53:06 GMT Date: Wed, 20 Nov 2002 14:53:01 +0000 From: Tim Bunce To: David Wheeler Cc: Jeff Urlwin , dbi-dev@perl.org, pgsql-interfaces@postgresql.org Subject: Re: :PgSQL: More Queestions Message-ID: <20021120145301.GY381@dansat.data-plan.com> References: <289E1136-FC56-11D6-8F04-0003931A964A@wheeler.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <289E1136-FC56-11D6-8F04-0003931A964A@wheeler.net> User-Agent: Mutt/1.4i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/128 X-Sequence-Number: 3376 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.