Re: :PgSQL: More Queestions

Поиск
Список
Период
Сортировка
От Tim Bunce
Тема Re: :PgSQL: More Queestions
Дата
Msg-id 20021120145301.GY381@dansat.data-plan.com
обсуждение исходный текст
Ответ на Re: :PgSQL: More Queestions  (David Wheeler <david@wheeler.net>)
Ответы Re: :PgSQL: More Queestions  (Rudy Lippan <rlippan@remotelinux.com>)
Список 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.


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Rudy Lippan
Дата:
Сообщение: Re: DBD::PgSQL: More Queestions
Следующее
От: Tim Bunce
Дата:
Сообщение: Re: DBD::PgSQL: More Queestions