From: David Johnston <polobo@yahoo.com>
To: 'GEISINGER Marc - Contractor' <Marc.GEISINGER@external.thalesgroup.com>
To: 'Dave Cramer' <pg@fastcrypt.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Bug in AbstracJdbc2Statement.replaceProcessing when using dollar quoting?
Date: Wed, 26 Sep 2012 10:58:07 -0400
Message-ID: <00f501cd9bf7$57195dc0$054c1940$@yahoo.com> (raw)
In-Reply-To: <32597_1348670307_50631363_32597_9347_1_E4DFA2E3210FA443B032684B39D16BB4092FB673AE@THSNCOA06MXS02P.ONE-06.GRP>
References: <31630_1348140231_505AFCC7_31630_19463_1_E4DFA2E3210FA443B032684B39D16BB4092FB05DA1@THSNCOA06MXS02P.ONE-06.GRP>
<CADK3HHLahcUgELs3Hp_R3EUn44pTuS4qahQUN1Tbhu6G5i=3RA@mail.gmail.com>
<20900_1348212583_505C1767_20900_6851_1_E4DFA2E3210FA443B032684B39D16BB4092FB06168@THSNCOA06MXS02P.ONE-06.GRP>
<012501cd9815$42b55e50$c8201af0$@yahoo.com>
<012c01cd9818$1ca45060$55ecf120$@yahoo.com>
<6830_1348470710_506007B6_6830_1428_1_E4DFA2E3210FA443B032684B39D16BB4092FB065BE@THSNCOA06MXS02P.ONE-06.GRP>
<CADK3HHJJjDp-W4oVcuKY79s+df1qWJLSQ9B8pLwx-zHDBp2Qtw@mail.gmail.com>
<6830_1348483308_506038EC_6830_5625_1_E4DFA2E3210FA443B032684B39D16BB4092FB6683E@THSNCOA06MXS02P.ONE-06.GRP>
<003e01cd9a6c$2b6ea770$824bf650$@yahoo.com>
<32597_1348670307_50631363_32597_9347_1_E4DFA2E3210FA443B032684B39D16BB4092FB673AE@THSNCOA06MXS02P.ONE-06.GRP>
> -----Ursprüngliche Nachricht-----
> Von: David Johnston [mailto:polobo@yahoo.com]
> Gesendet: Montag, 24. September 2012 17:49
> An: GEISINGER Marc - Contractor; 'Dave Cramer'
> Cc: pgsql-jdbc@postgresql.org
> Betreff: RE: [JDBC] Bug in AbstracJdbc2Statement.replaceProcessing when
> using dollar quoting?
>
>
> > At worse even if you cannot code it yourself you can propose pseudo-
> code/algorithm that people could review and then someone could just code
> > and deploy.
>
> Looking at
> http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html
>
> 4.1.1. Identifiers and Key Words
> ...
> SQL identifiers and key words must begin with a letter (a-z, but also
letters
> with diacritical marks and non-Latin letters) or an underscore (_).
Subsequent
> characters in an identifier or key word can be letters, underscores,
digits (0-
> 9), or dollar signs ($). Note that dollar signs are not allowed in
identifiers
> according to the letter of the SQL standard, so their use might render
> applications less portable.
>
> it seems to me, that $ are not allowed as identifiers by the SQL standard.
But
> they are allowed in postgresql. But also in postgresql they are not
allowed at
> the beginning of an identifier.
> As far as I understand the parseSql method (line 864) in
> AbstractJdbc2Statement class, the looking for a dollar quoted string could
be
> done similar to the looking for escape codes (line 894).
> If we are IN_SQLCODE and we find a '$' as character, look through the
> following chars until the next '$' is found. Anything between the two '$'
is the
> tag. Then we would have a state IN_DOLLARQOUTE, until we find this '$tag$'
> again.
> The only problem I see with this idea might come from nested dollar
quotes.
>
> Marc
Which is why my suggestion is possibly superior and at least simpler (thus
less prone to bugs).
Once you find the non-conforming dollar-quote start tag in the query simply
abort the JDBC specific code and return the query unmodified.
As I mentioned in a separate post a dollar-sign cannot begin the identifier
while it must begin the dollar-quote so we should be able to unambiguously
determine which of the two options is valid upon encountering a dollar-sign
without having to perform any further scan.
You now remove the "information losing" quality of the current behavior.
I'm personally willing to risk the breakage of existing mixed code on the
basis that such mixing is inconsistent with the goal of the standard in the
first place and thus is likely to be minimal at best. As a middle ground
the rest of the query should be scanned for JDBC escapes and, if found
(anywhere, even inside a dollar-quoted string), a RuntimeException sub-class
should be thrown pointing out the use of "mixed syntax".
That aside, nested quoting is not a concern; the string literal does not end
until the matching ending tag is found (i.e., at no point after encountering
a dollar-quote start tag does the parser state become IN_SQLCODE - until the
closing quote is matched).
David J.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: polobo@yahoo.com, Marc.GEISINGER@external.thalesgroup.com, pg@fastcrypt.com
Subject: Re: Bug in AbstracJdbc2Statement.replaceProcessing when using dollar quoting?
In-Reply-To: <00f501cd9bf7$57195dc0$054c1940$@yahoo.com>
References: <31630_1348140231_505AFCC7_31630_19463_1_E4DFA2E3210FA443B032684B39D16BB4092FB05DA1@THSNCOA06MXS02P.ONE-06.GRP> <CADK3HHLahcUgELs3Hp_R3EUn44pTuS4qahQUN1Tbhu6G5i=3RA@mail.gmail.com> <20900_1348212583_505C1767_20900_6851_1_E4DFA2E3210FA443B032684B39D16BB4092FB06168@THSNCOA06MXS02P.ONE-06.GRP> <012501cd9815$42b55e50$c8201af0$@yahoo.com> <012c01cd9818$1ca45060$55ecf120$@yahoo.com> <6830_1348470710_506007B6_6830_1428_1_E4DFA2E3210FA443B032684B39D16BB4092FB065BE@THSNCOA06MXS02P.ONE-06.GRP> <CADK3HHJJjDp-W4oVcuKY79s+df1qWJLSQ9B8pLwx-zHDBp2Qtw@mail.gmail.com> <6830_1348483308_506038EC_6830_5625_1_E4DFA2E3210FA443B032684B39D16BB4092FB6683E@THSNCOA06MXS02P.ONE-06.GRP> <003e01cd9a6c$2b6ea770$824bf650$@yahoo.com> <32597_1348670307_50631363_32597_9347_1_E4DFA2E3210FA443B032684B39D16BB4092FB673AE@THSNCOA06MXS02P.ONE-06.GRP> <00f501cd9bf7$57195dc0$054c1940$@yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox