Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D8AB7475925 for ; Thu, 21 Nov 2002 04:23:16 -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 CC82C4758DC for ; Thu, 21 Nov 2002 04:23:15 -0500 (EST) Received: (qmail 40593 messnum 1110767 invoked from network[159.134.166.43/p555.as1.limerick1.eircom.net]); 21 Nov 2002 09:23:16 -0000 Received: from p555.as1.limerick1.eircom.net (HELO dansat.data-plan.com) (159.134.166.43) by mail04.svc.cra.dublin.eircom.net (qp 40593) with SMTP; 21 Nov 2002 09:23:16 -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 gAL9NIao016981; Thu, 21 Nov 2002 09:23:18 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 gAL9NGi9016980; Thu, 21 Nov 2002 09:23:16 GMT Date: Thu, 21 Nov 2002 09:23:16 +0000 From: Tim Bunce To: David Wheeler Cc: Tim Bunce , Jeff Urlwin , dbi-dev@perl.org, pgsql-interfaces@postgresql.org Subject: Re: :PgSQL: More Queestions Message-ID: <20021121092316.GF381@dansat.data-plan.com> References: <20021120145301.GY381@dansat.data-plan.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/133 X-Sequence-Number: 3381 On Wed, Nov 20, 2002 at 10:30:00PM -0800, David Wheeler wrote: > On Wednesday, November 20, 2002, at 06:53 AM, Tim Bunce 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. > > Yes, your last post makes very clear why. Thanks. > > >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). > > Seems rather opaque. Maybe I'm just reflecting my C-newbieness, but why > wouldn't this work as well? Borrowing a bit from DBD::ODBC here (but > allowing for both kinds of escaping of the quote characters): > > if (*src == '"' || *src == '\'') { > if (!in_literal) { > literal_ch = *src; > in_literal = 1; No need for in_literal as literal_ch can serve as a flag as well. > } else { > if (*src == literal_ch && *(src-1) != '//' > && *(src-1) != literal_ch) { > in_literal = 0; > } > } > } Can't distinguish between "....\\\\" - final double quote ends the string "...\\\\\" - final double quote is escaped and string continues... If the original code isn't broken it doesn't need fixing, maybe just commenting. Tim.