pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: marc.mg75@googlemail.com
To: pgsql-jdbc@postgresql.org
Subject: Re: Bug in AbstracJdbc2Statement.replaceProcessing when using dollar quoting?
Date: Tue, 9 Oct 2012 04:15:00 -0700 (PDT)
Message-ID: <9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.com> (raw)
In-Reply-To: <CAF-4BpPaaiZuHX=6Rjtksuhf0PJYHDiroVRV3Yn4dFOEJqkhSw@mail.gmail.com>
References: <31630_1348140231_505AFCC7_31630_19463_1_E4DFA2E3210FA443B032684B39D16BB4092FB05DA1@THSNCOA06MXS02P.ONE-06.GRP>
	<00f501cd9bf7$57195dc0$054c1940$@yahoo.com>
	<5077_1348672047_50631A2F_5077_14708_1_E4DFA2E3210FA443B032684B39D16BB4092FB673D5@THSNCOA06MXS02P.ONE-06.GRP>
	<CAF-4BpPaaiZuHX=6Rjtksuhf0PJYHDiroVRV3Yn4dFOEJqkhSw@mail.gmail.com>

Am Donnerstag, 27. September 2012 15:02:28 UTC+2 schrieb Florent Guillaume:

> Oracle is well known for its V$SESSION and other similar tables.

Hi,
even if Oracle uses V$SESSIONs, the $ here is not at the beginning, and it also does not fit the sql standard.

I made a small patch doing what was said above. While parsing the sql code it checks if there is a $ while in the state IN_SQLCODE, if so it stops the parsing and returns the original sql.

I ran the testsuite and it passed with no error. I also checked my example and the result returned is what would be expected.


inline patch 1: /org/postgresql/jdbc2/AbstractJdbc2Statement.java (+12/-2 lines) download inline-1.patch--- /org/postgresql/jdbc2/AbstractJdbc2Statement.java_orig Tue Oct 09 10:25:10 2012 +++ /org/postgresql/jdbc2/AbstractJdbc2Statement.java Tue Oct 09 10:31:50 2012 @@ -895,6 +895,7 @@ int len = p_sql.length(); StringBuffer newsql = new StringBuffer(len); int i=0; + try { while (i<len){ i=parseSql(p_sql,i,newsql,false,connection.getStandardConformingStrings()); // We need to loop here in case we encounter invalid @@ -907,6 +908,11 @@ i++; } } + } catch (final PGDollarQuoteParsingException e) { + // found dollar quoting in the sql string. do not parse for + // escape clauses and return the original sql. + return p_sql; + } return newsql.toString(); } else @@ -929,7 +935,7 @@ * @return the position we stopped processing at */ protected static int parseSql(String p_sql,int i,StringBuffer newsql, boolean stopOnComma, - boolean stdStrings)throws SQLException{ + boolean stdStrings)throws SQLException, PGDollarQuoteParsingException { short state = IN_SQLCODE; int len = p_sql.length(); int nestedParenthesis=0; @@ -955,6 +961,10 @@ endOfNested=true; break; } + } else if (c == '$') { // start of a dollar quoted string + // dollar quoted strings are postgreSql only, throw an + // exception to stop parsing for db indepentend syntax. + throw new PGDollarQuoteParsingException(); } else if (stopOnComma && c==',' && nestedParenthesis==0) { endOfNested=true; break; @@ -1066,7 +1076,7 @@ * @param stdStrings whether standard_conforming_strings is on * @return the right postgreSql sql */ - protected static String escapeFunction(String functionName, String args, boolean stdStrings) throws SQLException{ + protected static String escapeFunction(String functionName, String args, boolean stdStrings) throws SQLException, PGDollarQuoteParsingException{ // parse function arguments int len = args.length(); int i=0;
And i added an exception for this: package org.postgresql.core; public class PGDollarQuoteParsingException extends Exception { } Using this exception i handle to stop the parsing. It could also be used to print a warning or whatever.

view thread (29+ messages)  latest in thread

Message-ID: <9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.com>
Permalink:  ../9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.com/
Also on:    postgresql.org/message-id/9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.com

 ·  · 

reply

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: marc.mg75@googlemail.com
  Subject: Re: Bug in AbstracJdbc2Statement.replaceProcessing when using dollar quoting?
  In-Reply-To: <9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.com>
  References: <31630_1348140231_505AFCC7_31630_19463_1_E4DFA2E3210FA443B032684B39D16BB4092FB05DA1@THSNCOA06MXS02P.ONE-06.GRP> <00f501cd9bf7$57195dc0$054c1940$@yahoo.com> <5077_1348672047_50631A2F_5077_14708_1_E4DFA2E3210FA443B032684B39D16BB4092FB673D5@THSNCOA06MXS02P.ONE-06.GRP> <CAF-4BpPaaiZuHX=6Rjtksuhf0PJYHDiroVRV3Yn4dFOEJqkhSw@mail.gmail.com> <9945522a-bc49-44e4-906b-cfdacc801b41@googlegroups.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