Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TGt4t-0001Dw-9B for pgsql-jdbc@postgresql.org; Wed, 26 Sep 2012 14:59:07 +0000 Received: from smtp106.prem.mail.ac4.yahoo.com ([76.13.13.45]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TGt4r-0004is-Be for pgsql-jdbc@postgresql.org; Wed, 26 Sep 2012 14:59:06 +0000 Received: (qmail 93328 invoked from network); 26 Sep 2012 14:59:04 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=l5SEWR3oAr3OddMt7Bb6QZsvZMXcZUtKqqVWi3YbaQCLpd9Tv8bi/F52NYcumRaDXc/iz8qQF3fBkovme7vzk0TpPhd7Ag0sC/gjpVG2AqeBMzZiyJCxNLTXeTZ8L7UbDO1ySuY3Xfb242r7Jp+oS1OvTIbYKKHZfYvU+2Ot4Kc= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1348671544; bh=SMgBhCtG2K58t2m2knCanOmqWN5w0Kj3/gybHkyLqOY=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=bNBExwWmw1FHJBBrDG+XQBmguA8joowQEeFwmoeT6y95m/2waiaWjBb8u1uzYm1kMzyB9pyk7QB7JLmtvzQqRh65M6CUQH5FIT7+40+XvXM83wdIe31FM7s2f+GJfh9eYLocaasTKAkwqZEgiBphv50FWj3n7VStqjkavFV7ui8= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 8LiAPy8VM1kzzVStyTx2IXgg0_rithEUoj740hEChRAcCDf OQTjVj_hrJYSD_u..8xbHx9_fEYIb9MH_UASr.DGdWyArWpgeK5zClUrw3hJ aaaJ9xAKSkQOG08C8y9UOovlJjx1XcWsWdFVXJ2dsFFkx8S467XGVFVUOshH Gj9kwAxfkyxwWoS.10owYCeDFOYtH6tPeYwzPAbgjqCFIIx4KGxjxU4f0jCd bvqZ39nsyn3Ootanpad.APgP1YjE7idvp88CnrVTZmimupYgZgfNgncbGZ9j OAGa5WLmqSJ3Fz8Qsh5Y1VGgbWWBJZGP0mGKvA5CyQk2tRXRMhbeW7nmL181 5p0ZpK46U9En3JEfOf7e2gR5HFY48AvLZdfYaYwkoB_SdGwvy9BnBsTSTCT5 8I6.cMGDkiEO9wdyA4Yb3uq6681kkGz1MUCd5hMM9GWZLBdbnWmS9oXJnxZK AAb4O X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp106.prem.mail.ac4.yahoo.com with SMTP; 26 Sep 2012 07:59:03 -0700 PDT From: "David Johnston" To: "'GEISINGER Marc - Contractor'" , "'Dave Cramer'" Cc: References: <31630_1348140231_505AFCC7_31630_19463_1_E4DFA2E3210FA443B032684B39D16BB4092FB05DA1@THSNCOA06MXS02P.ONE-06.GRP> <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> <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> In-Reply-To: <32597_1348670307_50631363_32597_9347_1_E4DFA2E3210FA443B032684B39D16BB4092FB673AE@THSNCOA06MXS02P.ONE-06.GRP> 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> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQI+ZV0iQ92YvBLV3Nq2AMHb27DsQQD4mz0iAjnGRI0BptNbhAJv2iczAbC7PwoBa8OOGQIPitpZAoQLqSIA30eUbZY8XNgA Content-Language: en-us X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201209/77 X-Sequence-Number: 23313 > -----Urspr=FCngliche 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? >=20 >=20 > > 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. >=20 > Looking at > http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html >=20 > 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. >=20 > 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. >=20 > Marc Which is why my suggestion is possibly superior and at least simpler = (thus less prone to bugs).=20 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.