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.