Re: [HACKERS] dollar quoting

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] dollar quoting
Date: 2004-02-09 15:37:38
Message-ID: 4027A942.1080905@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


I think the attached patch addresses Tom's comments.

I ended up not using a regex, which seemed to be a little heavy handed,
but just writing a small custom recognition function, that should (and I
think does) mimic the pattern recognition for these tokens used by the
backend lexer. This patch just puts that function in mainloop.c, but
perhaps it belongs elsewhere (string_utils.c maybe?). I don't have
strong opinions on that.

Enjoy

andrew

Tom Lane wrote:

>Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>
>>Comments welcome. Reviewers: I am not sure I got multi-byte stuff right
>>in psql/mainloop.c - please pay close attention to that.
>>
>>
>
>The i-1 stuff should generally be i-prevlen. Not sure if there are any
>other pitfalls.
>
>A bigger problem here:
>
>
>
>>+ else if (!dol_quote && line[i] == '$' &&
>>+ !isdigit(line[i + thislen]) &&
>>+ (dol_end = strchr(line+i+1,'$')) != NULL &&
>>+ (i == 0 ||
>>+ ! ((line[i-1] & 0x80) != 0 || isalnum(line[i-1]) ||
>>+ line[i-1] == '_')))
>>+ {
>>
>>
>
>is that you aren't checking that what comes between the two dollar signs
>looks like empty-or-an-identifier. The check for
>next-char-isn't-a-digit is part of that but not the only part.
>
>Also I'm not sure about the positioning of these tests relative to the
>in_quote and in_xcomment tests. As you have it, $foo$ will be
>recognized within an xcomment, which I think is at variance with the
>proposed backend lexing behavior.
>
>Also, the strdup should be pg_strdup.
>
> regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
>
>

Attachment Content-Type Size
dq-amd2.patch text/plain 8.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alex J. Avriette 2004-02-09 15:37:55 Re: RFC: Security documentation
Previous Message Tom Lane 2004-02-09 15:30:13 Re: Transaction aborts on syntax error.

Browse pgsql-patches by date

  From Date Subject
Next Message Michael Glaesemann 2004-02-09 15:58:47 Linking references in documentation
Previous Message Mark Cave-Ayland 2004-02-09 14:28:22 Re: ANALYZE patch for review