From: Kris Jurka <books@ejurka.com>
To: Michael Paesold <mpaesold@gmx.at>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Altaf Malik <mmalik_altaf@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Unable to prepare a statement when the object names contain more than one $ symbol
Date: Tue, 16 Oct 2007 04:22:25 -0400 (EDT)
Message-ID: <Pine.BSO.4.64.0710160420230.644@leary.csoft.net> (raw)
In-Reply-To: <46937FCD.7060409@gmx.at>
References: <540504.87872.qm@web39103.mail.mud.yahoo.com>
<Pine.BSO.4.64.0707091229520.10973@leary.csoft.net>
<23286.1183999558@sss.pgh.pa.us>
<46937FCD.7060409@gmx.at>
On Tue, 10 Jul 2007, Michael Paesold wrote:
> Tom Lane schrieb:
>> Kris Jurka <books@ejurka.com> writes:
>>> On Mon, 9 Jul 2007, Altaf Malik wrote:
>>>> PreparedStatement pstmt = con.prepareStatement("insert into a$b$c values(
>>>> ? , ?)");
>>
>>> This is a bug in dollar quote parsing. It assumes that any potential
>>> dollar quote start will have an end tag.
>>
>> If it thinks that's a dollar quote start, it's wrong already... that's
>> a perfectly valid table name. (Although personally I'd suggest that the
>> OP avoid dollar signs in identifiers, since they're none too portable.)
>
> I guess I missed that case when implementing dollar quoting in the driver. I
> will have a look at it shortly.
>
Did you ever get a chance to look at this? The attached patch fixes the
original complaint by ensuring that the ending tag exists, but as Tom
pointed out that's still not good enough as the second attached test case
demonstrates.
Kris Jurka
Attachments:ensure-dollarquote-ends.patch (text/plain, 1.5K) download
? build.local.properties
? ensure-dollarquote-ends.patch
Index: org/postgresql/core/Parser.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/core/Parser.java,v
retrieving revision 1.2
diff -c -r1.2 Parser.java
*** org/postgresql/core/Parser.java 1 Dec 2006 08:53:45 -0000 1.2
--- org/postgresql/core/Parser.java 16 Oct 2007 08:18:31 -0000
***************
*** 89,94 ****
--- 89,95 ----
* character.
*/
public static int parseDollarQuotes(final char[] query, int offset) {
+ int endOffset = offset;
if (offset + 1 < query.length)
{
int endIdx = -1;
***************
*** 117,129 ****
if (query[offset] == '$' &&
subArraysEqual(query, tagIdx, offset, tagLen))
{
! offset += tagLen - 1;
break;
}
}
}
}
! return offset;
}
/**
--- 118,130 ----
if (query[offset] == '$' &&
subArraysEqual(query, tagIdx, offset, tagLen))
{
! endOffset = offset + tagLen - 1;
break;
}
}
}
}
! return endOffset;
}
/**
DollarTest.java (text/plain, 1018B) download
import java.sql.*;
public class DollarTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka?loglevel=2","jurka","");
test1(conn);
test2(conn);
conn.close();
}
private static void test1(Connection conn) throws SQLException
{
conn.createStatement().execute("CREATE TEMP TABLE a$b$c(a varchar, b varchar) ");
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO a$b$c (a, b) VALUES (?, ?) ");
pstmt.setString(1, "a");
pstmt.setString(2, "b");
pstmt.executeUpdate();
pstmt.close();
}
private static void test2(Connection conn) throws SQLException
{
conn.createStatement().execute("CREATE TEMP TABLE e$f$g(h varchar, e$f$g varchar) ");
PreparedStatement pstmt = conn.prepareStatement("UPDATE e$f$g SET h = ? || e$f$g");
pstmt.setString(1, "a");
pstmt.executeUpdate();
pstmt.close();
}
}
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: books@ejurka.com, mpaesold@gmx.at, tgl@sss.pgh.pa.us, mmalik_altaf@yahoo.com
Subject: Re: Unable to prepare a statement when the object names contain more than one $ symbol
In-Reply-To: <Pine.BSO.4.64.0710160420230.644@leary.csoft.net>
References: <540504.87872.qm@web39103.mail.mud.yahoo.com> <Pine.BSO.4.64.0707091229520.10973@leary.csoft.net> <23286.1183999558@sss.pgh.pa.us> <46937FCD.7060409@gmx.at> <Pine.BSO.4.64.0710160420230.644@leary.csoft.net>
* 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