pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feeddollar quoting
13+ messages / 4 participants
[nested] [flat]
* dollar quoting
@ 2006-10-03 15:54 Jure Koren <jure@hehe.si>
2006-10-03 16:48 ` Re: dollar quoting Michael Paesold <mpaesold@gmx.at>
2006-10-03 16:58 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
0 siblings, 3 replies; 13+ messages in thread
From: Jure Koren @ 2006-10-03 15:54 UTC (permalink / raw)
To: pgsql-jdbc
Hello!
I've added dollar quoting support to the 8.2dev-503 version query parser.
Where should I send the patch?
--
Jure Koren, unix developer
Hehe d.o.o.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 16:48 ` Michael Paesold <mpaesold@gmx.at>
2 siblings, 0 replies; 13+ messages in thread
From: Michael Paesold @ 2006-10-03 16:48 UTC (permalink / raw)
To: Jure Koren <jure@hehe.si>; +Cc: pgsql-jdbc
Jure Koren wrote:
> Hello!
>
> I've added dollar quoting support to the 8.2dev-503 version query parser.
>
> Where should I send the patch?
I have just recently sent a patch for dollar quoting to this list and I am
waiting for feedback now. :-)
Michael
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 16:58 ` Dave Cramer <pg@fastcrypt.com>
2 siblings, 0 replies; 13+ messages in thread
From: Dave Cramer @ 2006-10-03 16:58 UTC (permalink / raw)
To: Jure Koren <jure@hehe.si>; +Cc: pgsql-jdbc
Jure,
Please send a context diff to this list, and perhaps you may want to
read this
http://archives.postgresql.org/pgsql-jdbc/2006-10/msg00000.php
Dave
On 3-Oct-06, at 11:54 AM, Jure Koren wrote:
> Hello!
>
> I've added dollar quoting support to the 8.2dev-503 version query
> parser.
>
> Where should I send the patch?
>
> --
> Jure Koren, unix developer
> Hehe d.o.o.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 17:00 ` Jure Koren <jure@hehe.si>
2006-10-03 17:03 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2 siblings, 2 replies; 13+ messages in thread
From: Jure Koren @ 2006-10-03 17:00 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 03 October 2006 17:54, Jure Koren wrote:
> Hello!
> I've added dollar quoting support to the 8.2dev-503 version query parser.
Well, it's really not that big, so here it is.
Though it works for me and I've tried to read the dollar quoting definition in
the postgresql docs several times, I can't really be sure if it's correct :)
If anyone bothers enough with it to find a problem, you can let me know.
Regards,
--
Jure Koren, unix developer
Hehe d.o.o.
Attachments:
postgresql-jdbc-dollarquote.diff (text/x-diff, 1.0K) download
diff -ru postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java
--- postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java 2006-04-29 15:30:24.000000000 +0200
+++ postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 17:41:06.000000000 +0200
@@ -99,6 +99,21 @@
}
break;
+ case '$':
+ int pos = query.indexOf('$', i+1);
+ if (pos < 0)
+ break;
+ String tag = query.substring(i+1, pos);
+ String nexttag = new StringBuilder(tag).insert(0, "$").append("$").toString();
+ int nextpos = query.indexOf(nexttag, pos+1);
+ if (nextpos < 0)
+ break;
+ i = nextpos + tag.length() + 2;
+ break;
+
case '(':
if (!inSingleQuotes && !inDoubleQuotes)
inParen++;
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 17:03 ` Jure Koren <jure@hehe.si>
1 sibling, 0 replies; 13+ messages in thread
From: Jure Koren @ 2006-10-03 17:03 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 03 October 2006 19:00, Jure Koren wrote:
> Well, it's really not that big, so here it is.
And, naturally, I attached the one that is broken.
Here it is, again.
--
Jure Koren, unix developer
Hehe d.o.o.
Attachments:
postgresql-jdbc-dollarquote.diff (text/x-diff, 1.3K) download
diff -ru postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java
--- postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 18:01:47.000000000 +0200
+++ postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 18:42:03.000000000 +0200
@@ -99,6 +99,39 @@
}
break;
+ case '$':
+ if (inDoubleQuotes || inSingleQuotes)
+ break;
+ int pos = query.indexOf('$', i+1);
+ if (pos < 0)
+ break;
+ String tag = query.substring(i+1, pos);
+ String nexttag = new StringBuilder(tag).insert(0, "$").append("$").toString();
+ //System.out.println("next tag = (" + nexttag + ")");
+ //System.out.println("begin =\n(" + query.substring(i-10, pos+10) + ")");
+ int nextpos = query.indexOf(nexttag, pos+1);
+ if (nextpos < 0)
+ break;
+ i = nextpos + tag.length() + 2;
+ //System.out.println("end =\n(" + query.substring(i-10, i+tag.length()+10) + ")");
+ break;
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 17:05 ` Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 13+ messages in thread
From: Dave Cramer @ 2006-10-03 17:05 UTC (permalink / raw)
To: Jure Koren <jure@hehe.si>; +Cc: pgsql-jdbc
Jure,
On 3-Oct-06, at 1:00 PM, Jure Koren wrote:
> On Tuesday 03 October 2006 17:54, Jure Koren wrote:
>> Hello!
>> I've added dollar quoting support to the 8.2dev-503 version query
>> parser.
>
> Well, it's really not that big, so here it is.
>
> Though it works for me and I've tried to read the dollar quoting
> definition in
> the postgresql docs several times, I can't really be sure if it's
> correct :)
>
> If anyone bothers enough with it to find a problem, you can let me
> know.
Isn't StringBuilder a jdk 1.5 only function ?
>
> Regards,
>
> --
> Jure Koren, unix developer
> Hehe d.o.o.
> <postgresql-jdbc-dollarquote.diff>
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
@ 2006-10-03 18:14 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
0 siblings, 1 reply; 13+ messages in thread
From: Tom Lane @ 2006-10-03 18:14 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Jure Koren <jure@hehe.si>; pgsql-jdbc
Dave Cramer <pg@fastcrypt.com> writes:
>> On Tuesday 03 October 2006 17:54, Jure Koren wrote:
>>> I've added dollar quoting support to the 8.2dev-503 version query
>>> parser.
> Isn't StringBuilder a jdk 1.5 only function ?
Also, this patch is not being nearly cautious enough about what is a
valid dollar-quote start sequence. The other patch that was proposed
looked more reasonable on that score.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
@ 2006-10-03 19:38 ` Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Re: dollar quoting Jure Koren <jure@hehe.si>
0 siblings, 1 reply; 13+ messages in thread
From: Jure Koren @ 2006-10-03 19:38 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 03 October 2006 20:14, Tom Lane wrote:
> Also, this patch is not being nearly cautious enough about what is a
> valid dollar-quote start sequence. The other patch that was proposed
> looked more reasonable on that score.
Yes.
This is the version that I think addresses most of the concerns posted.
Thank you for your feedback.
--
Jure Koren, unix developer
Hehe d.o.o.
Attachments:
postgresql-jdbc-dollarquote.diff (text/x-diff, 1.1K) download
diff -ru postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java
--- postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 19:06:00.000000000 +0200
+++ postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 21:34:34.000000000 +0200
@@ -99,6 +99,21 @@
}
break;
+ case '$':
+ if (inDoubleQuotes || inSingleQuotes)
+ break;
+ int pos = query.indexOf('$', i+1);
+ if (pos < 0)
+ break;
+ String tag = query.substring(i, pos+1);
+ if (!tag.matches("^\\$[\\p{L}_][\\p{L}\\d_]*\\$$"))
+ break;
+ int nextpos = query.indexOf(tag, pos+1);
+ if (nextpos < 0)
+ break;
+ i = nextpos + tag.length() + 2;
+ break;
+
case '(':
if (!inSingleQuotes && !inDoubleQuotes)
inParen++;
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 19:46 ` Jure Koren <jure@hehe.si>
2006-10-03 19:54 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 20:13 ` Re: dollar quoting Michael Paesold <mpaesold@gmx.at>
0 siblings, 2 replies; 13+ messages in thread
From: Jure Koren @ 2006-10-03 19:46 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 03 October 2006 21:38, Jure Koren wrote:
> This is the version that I think addresses most of the concerns posted.
Except for the empty ($$) tag, which this, hopefully last version, does as
well.
Sorry, i haven't slept for a while.
--
Jure Koren, unix developer
Hehe d.o.o.
Attachments:
postgresql-jdbc-dollarquote.diff (text/x-diff, 1.5K) download
Only in postgresql-jdbc-8.2dev-503.src-dq: build
Only in postgresql-jdbc-8.2dev-503.src-dq: jars
diff -ru postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java
--- postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 19:06:00.000000000 +0200
+++ postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/core/v3/QueryExecutorImpl.java 2006-10-03 21:40:36.000000000 +0200
@@ -99,6 +99,21 @@
}
break;
+ case '$':
+ if (inDoubleQuotes || inSingleQuotes)
+ break;
+ int pos = query.indexOf('$', i+1);
+ if (pos < 0)
+ break;
+ String tag = query.substring(i, pos+1);
+ if (!tag.matches("^\\$([\\p{L}_][\\p{L}\\d_]*)?\\$$"))
+ break;
+ int nextpos = query.indexOf(tag, pos+1);
+ if (nextpos < 0)
+ break;
+ i = nextpos + tag.length() + 2;
+ break;
+
case '(':
if (!inSingleQuotes && !inDoubleQuotes)
inParen++;
Only in postgresql-jdbc-8.2dev-503.src/org/postgresql/core/v3: QueryExecutorImpl.java.orig
Only in postgresql-jdbc-8.2dev-503.src-dq/org/postgresql: Driver.java
Only in postgresql-jdbc-8.2dev-503.src-dq/org/postgresql/util: PSQLException.java
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 19:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 20:36 ` Re: dollar quoting Jure Koren <jure@hehe.si>
1 sibling, 1 reply; 13+ messages in thread
From: Tom Lane @ 2006-10-03 19:54 UTC (permalink / raw)
To: Jure Koren <jure@hehe.si>; +Cc: pgsql-jdbc
Jure Koren <jure@hehe.si> writes:
>> This is the version that I think addresses most of the concerns posted.
> Except for the empty ($$) tag, which this, hopefully last version, does as
> well.
No ... a locale-dependent character class test is exactly the wrong
thing. See the other discussion.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:54 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
@ 2006-10-03 20:36 ` Jure Koren <jure@hehe.si>
2006-10-03 20:51 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: Jure Koren @ 2006-10-03 20:36 UTC (permalink / raw)
To: pgsql-jdbc
On Tuesday 03 October 2006 21:54, Tom Lane wrote:
> No ... a locale-dependent character class test is exactly the wrong
> thing. See the other discussion.
But it isn't locale dependent. All unicode letter class character match,
regardless of locale (which is what the postgres docs say as well).
Yes, probably not the best thing to do, but my reasoning was that dollar
quoting is going to be used by humans writing functions. Using dollar
escaping in non-ddl stuff is, i think, extremely unlikely, as normal escaping
functions will normally take care of those cases.
Michael Paesold <mpaesold@gmx.at> wrote:
> - Having said that, I don't believe in compiling a regular expression for
> each dollar-quoted string and each $ character that is not part of a dollar
> quote
Yes, and I've noticed there's a missing test for leading whitespace, which
would make this fail very fast if it in fact wasn't a dollar quote. I'm
incapable of producing any more code today, but I'll be certainly improving
it later this week.
I'm not actually familiar with Java, so verbose criticism is most welcome,
off-list too. And i'm subscribed to the list, so you don't have to make
copies :)
Thank you for all the feedback and good night.
--
Jure Koren, unix developer
Hehe d.o.o.
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:54 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 20:36 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 20:51 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 13+ messages in thread
From: Tom Lane @ 2006-10-03 20:51 UTC (permalink / raw)
To: Jure Koren <jure@hehe.si>; +Cc: pgsql-jdbc
Jure Koren <jure@hehe.si> writes:
> On Tuesday 03 October 2006 21:54, Tom Lane wrote:
>> No ... a locale-dependent character class test is exactly the wrong
>> thing. See the other discussion.
> But it isn't locale dependent. All unicode letter class character match,
> regardless of locale (which is what the postgres docs say as well).
The point is that it's the wrong thing because it doesn't match what the
backend does: all characters > 127 are allowed in dollar tags, no matter
whether Java thinks they are letters or not.
regards, tom lane
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: dollar quoting
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:00 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Re: dollar quoting Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Re: dollar quoting Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Re: dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Re: dollar quoting Jure Koren <jure@hehe.si>
@ 2006-10-03 20:13 ` Michael Paesold <mpaesold@gmx.at>
1 sibling, 0 replies; 13+ messages in thread
From: Michael Paesold @ 2006-10-03 20:13 UTC (permalink / raw)
To: pgsql-jdbc
Jure Koren wrote:
> On Tuesday 03 October 2006 21:38, Jure Koren wrote:
>> This is the version that I think addresses most of the concerns posted.
>
> Except for the empty ($$) tag, which this, hopefully last version, does as
> well.
Some more comments:
- I don't think the regular expression is quite there yet, look at the code
in the other patch -- the "c > 127" part
- Having said that, I don't believe in compiling a regular expression for
each dollar-quoted string and each $ character that is not part of a dollar
quote
- There must be something wrong with this line at the end of a dollar-quote:
i = nextpos + tag.length() + 2;
My other patch has this here:
i += dollarQuoteTag.length() - 1;
"nextpos" in the first case should be the same as "i" in the second case.
Something like ..$$String$$; SELECT ... will break here, I guess. My patch
included JUnit tests to detect such off-by-one-or-more errors. You could
use them.
I am now wondering which version has the better performance... especially I
would like to know if switching between scanning the char[] and the
original query string in this patch has any negative impact. If not, it
could be applied quite easily to the other one. Perhaps you could evaluate
both versions for performance?
Best Regards,
Michael Paesold
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2006-10-03 20:51 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-10-03 15:54 dollar quoting Jure Koren <jure@hehe.si>
2006-10-03 16:48 ` Michael Paesold <mpaesold@gmx.at>
2006-10-03 16:58 ` Dave Cramer <pg@fastcrypt.com>
2006-10-03 17:00 ` Jure Koren <jure@hehe.si>
2006-10-03 17:03 ` Jure Koren <jure@hehe.si>
2006-10-03 17:05 ` Dave Cramer <pg@fastcrypt.com>
2006-10-03 18:14 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 19:38 ` Jure Koren <jure@hehe.si>
2006-10-03 19:46 ` Jure Koren <jure@hehe.si>
2006-10-03 19:54 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 20:36 ` Jure Koren <jure@hehe.si>
2006-10-03 20:51 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-03 20:13 ` Michael Paesold <mpaesold@gmx.at>
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