Re: Re: Escape Processing problems

Lists: pgsql-jdbc
From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Escape Processing problems
Date: 2001-08-28 14:57:21
Message-ID: 20010828235721.H32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi all,

The Connection.EscapeSQL() routine is broken IMHO . Actually, I'm not
sure why it is trying to fix strings starting with "{d" in the first place?

Anyway, currently I've turned it off in the statement with
setEscapeProcessing(false)

The problem I'm having is that "{d" appears in the data that I'm trying
to store and its not a date. So data like the following...

.....blahhh}; {blahhh }; {docs=""};

is turning into...

.....blahhh}; {blahhh }; ocs="" ;
^^ ^

What's more is if I have something like "{d....." and there is no ending
brace, it will throw a StringIndexOutOfBoundsException as the return
value of the indexOf() looking for the closing brace will not find one
and thus setCharAt() will use an illegal index of -1 :(

The routine is below for reference... Can anyone explain why it is trying
to do this on me in the first place. I would think escape processing would
do something a little different like watching my single quotes etc.

public String EscapeSQL(String sql) {
//if (DEBUG) { System.out.println ("parseSQLEscapes called"); }

// If we find a "{d", assume we have a date escape.
//
// Since the date escape syntax is very close to the
// native Postgres date format, we just remove the escape
// delimiters.
//
// This implementation could use some optimization, but it has
// worked in practice for two years of solid use.
int index = sql.indexOf("{d");
while (index != -1) {
//System.out.println ("escape found at index: " + index);
StringBuffer buf = new StringBuffer(sql);
buf.setCharAt(index, ' ');
buf.setCharAt(index + 1, ' ');
buf.setCharAt(sql.indexOf('}', index), ' ');
sql = new String(buf);
index = sql.indexOf("{d");
}
//System.out.println ("modified SQL: " + sql);
return sql;
}

Cheers,

Tom.
--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs


From: Barry Lind <barry(at)xythos(dot)com>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Escape Processing problems
Date: 2001-08-28 19:55:19
Message-ID: 3B8BF727.2030506@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Thomas,

This is doing exactly what it is supposed to according to the JDBC Spec.
In fact there are a bunch of other '{X }' things that the Spec
defines that it should also be handling.

thanks,
--Barry

Thomas O'Dowd wrote:
> Hi all,
>
> The Connection.EscapeSQL() routine is broken IMHO . Actually, I'm not
> sure why it is trying to fix strings starting with "{d" in the first place?
>
> Anyway, currently I've turned it off in the statement with
> setEscapeProcessing(false)
>
> The problem I'm having is that "{d" appears in the data that I'm trying
> to store and its not a date. So data like the following...
>
> .....blahhh}; {blahhh }; {docs=""};
>
> is turning into...
>
> .....blahhh}; {blahhh }; ocs="" ;
> ^^ ^
>
> What's more is if I have something like "{d....." and there is no ending
> brace, it will throw a StringIndexOutOfBoundsException as the return
> value of the indexOf() looking for the closing brace will not find one
> and thus setCharAt() will use an illegal index of -1 :(
>
> The routine is below for reference... Can anyone explain why it is trying
> to do this on me in the first place. I would think escape processing would
> do something a little different like watching my single quotes etc.
>
> public String EscapeSQL(String sql) {
> //if (DEBUG) { System.out.println ("parseSQLEscapes called"); }
>
> // If we find a "{d", assume we have a date escape.
> //
> // Since the date escape syntax is very close to the
> // native Postgres date format, we just remove the escape
> // delimiters.
> //
> // This implementation could use some optimization, but it has
> // worked in practice for two years of solid use.
> int index = sql.indexOf("{d");
> while (index != -1) {
> //System.out.println ("escape found at index: " + index);
> StringBuffer buf = new StringBuffer(sql);
> buf.setCharAt(index, ' ');
> buf.setCharAt(index + 1, ' ');
> buf.setCharAt(sql.indexOf('}', index), ' ');
> sql = new String(buf);
> index = sql.indexOf("{d");
> }
> //System.out.println ("modified SQL: " + sql);
> return sql;
> }
>
> Cheers,
>
> Tom.
>


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Barry Lind <barry(at)xythos(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Escape Processing problems
Date: 2001-08-29 00:18:26
Message-ID: 20010829091826.L32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi Barry,

I found the part in the spec that talks about escape processing for
date and time. Thanks for pointing that out. I believe the drivers
implementation is wrong as it is a) changing random text data instead
of data of a defined format to its escape sequence and b) it can throw
a out of bounds exception if there is no closing }.

Perhaps, I'll write a patch later in the day to fix this for at least
the date escape as that is the only one that is implemented.

So just to clarify my understanding of what should happen...

"SELECT a, b from c where t={d 'yyyy-mm-dd'} and a=1"

should be changed to:

"SELECT a, b from c where t='yyyy-mm-dd' and a=1"

and something like

"INSERT INTO test VALUES('don't change this {d 'yyyy-mm-dd'} as its correct. "

should be left alone. ie, if we're in a string escape processing should
not be done. Right now it looks for anything with {d in the query and
starts changing it.

Cheers,

Tom.

On Tue, Aug 28, 2001 at 12:55:19PM -0700, Barry Lind wrote:
> Thomas,
>
> This is doing exactly what it is supposed to according to the JDBC Spec.
> In fact there are a bunch of other '{X }' things that the Spec
> defines that it should also be handling.
>
> thanks,
> --Barry
>
> Thomas O'Dowd wrote:
> > Hi all,
> >
> > The Connection.EscapeSQL() routine is broken IMHO . Actually, I'm not
> > sure why it is trying to fix strings starting with "{d" in the first place?
> >
> > Anyway, currently I've turned it off in the statement with
> > setEscapeProcessing(false)
> >
> > The problem I'm having is that "{d" appears in the data that I'm trying
> > to store and its not a date. So data like the following...
> >
> > .....blahhh}; {blahhh }; {docs=""};
> >
> > is turning into...
> >
> > .....blahhh}; {blahhh }; ocs="" ;
> > ^^ ^
> >
> > What's more is if I have something like "{d....." and there is no ending
> > brace, it will throw a StringIndexOutOfBoundsException as the return
> > value of the indexOf() looking for the closing brace will not find one
> > and thus setCharAt() will use an illegal index of -1 :(
> >
> > The routine is below for reference... Can anyone explain why it is trying
> > to do this on me in the first place. I would think escape processing would
> > do something a little different like watching my single quotes etc.
> >
> > public String EscapeSQL(String sql) {
> > //if (DEBUG) { System.out.println ("parseSQLEscapes called"); }
> >
> > // If we find a "{d", assume we have a date escape.
> > //
> > // Since the date escape syntax is very close to the
> > // native Postgres date format, we just remove the escape
> > // delimiters.
> > //
> > // This implementation could use some optimization, but it has
> > // worked in practice for two years of solid use.
> > int index = sql.indexOf("{d");
> > while (index != -1) {
> > //System.out.println ("escape found at index: " + index);
> > StringBuffer buf = new StringBuffer(sql);
> > buf.setCharAt(index, ' ');
> > buf.setCharAt(index + 1, ' ');
> > buf.setCharAt(sql.indexOf('}', index), ' ');
> > sql = new String(buf);
> > index = sql.indexOf("{d");
> > }
> > //System.out.println ("modified SQL: " + sql);
> > return sql;
> > }
> >
> > Cheers,
> >
> > Tom.
> >
>
>

--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Barry Lind <barry(at)xythos(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-08-29 00:28:30
Message-ID: 20010829092830.M32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Wed, Aug 29, 2001 at 09:18:26AM +0900, Thomas O'Dowd wrote:
> "INSERT INTO test VALUES('don't change this {d 'yyyy-mm-dd'} as its correct. "

Opps. I didn't backslash the single quotes here but you know what I mean...

Tom.


From: Barry Lind <barry(at)xythos(dot)com>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Escape Processing problems
Date: 2001-08-29 01:24:06
Message-ID: 3B8C4436.5000900@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Thomas,

I can see where there might be bugs in the implementation of this
escaping stuff. I don't think it is used very often. I believe your
understanding of how this is supposed to work is correct.

thanks,
--Barry

Thomas O'Dowd wrote:
> Hi Barry,
>
> I found the part in the spec that talks about escape processing for
> date and time. Thanks for pointing that out. I believe the drivers
> implementation is wrong as it is a) changing random text data instead
> of data of a defined format to its escape sequence and b) it can throw
> a out of bounds exception if there is no closing }.
>
> Perhaps, I'll write a patch later in the day to fix this for at least
> the date escape as that is the only one that is implemented.
>
> So just to clarify my understanding of what should happen...
>
> "SELECT a, b from c where t={d 'yyyy-mm-dd'} and a=1"
>
> should be changed to:
>
> "SELECT a, b from c where t='yyyy-mm-dd' and a=1"
>
> and something like
>
> "INSERT INTO test VALUES('don't change this {d 'yyyy-mm-dd'} as its correct. "
>
> should be left alone. ie, if we're in a string escape processing should
> not be done. Right now it looks for anything with {d in the query and
> starts changing it.
>
> Cheers,
>
> Tom.
>
> On Tue, Aug 28, 2001 at 12:55:19PM -0700, Barry Lind wrote:
>
>>Thomas,
>>
>>This is doing exactly what it is supposed to according to the JDBC Spec.
>> In fact there are a bunch of other '{X }' things that the Spec
>>defines that it should also be handling.
>>
>>thanks,
>>--Barry
>>
>>Thomas O'Dowd wrote:
>>
>>>Hi all,
>>>
>>>The Connection.EscapeSQL() routine is broken IMHO . Actually, I'm not
>>>sure why it is trying to fix strings starting with "{d" in the first place?
>>>
>>>Anyway, currently I've turned it off in the statement with
>>>setEscapeProcessing(false)
>>>
>>>The problem I'm having is that "{d" appears in the data that I'm trying
>>>to store and its not a date. So data like the following...
>>>
>>>.....blahhh}; {blahhh }; {docs=""};
>>>
>>>is turning into...
>>>
>>>.....blahhh}; {blahhh }; ocs="" ;
>>> ^^ ^
>>>
>>>What's more is if I have something like "{d....." and there is no ending
>>>brace, it will throw a StringIndexOutOfBoundsException as the return
>>>value of the indexOf() looking for the closing brace will not find one
>>>and thus setCharAt() will use an illegal index of -1 :(
>>>
>>>The routine is below for reference... Can anyone explain why it is trying
>>>to do this on me in the first place. I would think escape processing would
>>>do something a little different like watching my single quotes etc.
>>>
>>> public String EscapeSQL(String sql) {
>>> //if (DEBUG) { System.out.println ("parseSQLEscapes called"); }
>>>
>>> // If we find a "{d", assume we have a date escape.
>>> //
>>> // Since the date escape syntax is very close to the
>>> // native Postgres date format, we just remove the escape
>>> // delimiters.
>>> //
>>> // This implementation could use some optimization, but it has
>>> // worked in practice for two years of solid use.
>>> int index = sql.indexOf("{d");
>>> while (index != -1) {
>>> //System.out.println ("escape found at index: " + index);
>>> StringBuffer buf = new StringBuffer(sql);
>>> buf.setCharAt(index, ' ');
>>> buf.setCharAt(index + 1, ' ');
>>> buf.setCharAt(sql.indexOf('}', index), ' ');
>>> sql = new String(buf);
>>> index = sql.indexOf("{d");
>>> }
>>> //System.out.println ("modified SQL: " + sql);
>>> return sql;
>>> }
>>>
>>>Cheers,
>>>
>>>Tom.
>>>
>>>
>>
>


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Barry Lind <barry(at)xythos(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Escape Processing problems
Date: 2001-08-30 02:46:16
Message-ID: 20010830114616.H32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi all,

I found some time this morning to write and test a new EscapeSQL() method.
I didn't make a patch for the driver yet as I'd like to hear some
comments. It's a tad longer than the original code as it only replaces
escape codes which appear in the SQL code and not inside strings.

It's attached as a separate java program which you can run to test with
various strings. Let me know if you think it is okay. It seems to work
with what I've tested it with.

Example:
$ /usr/local/java/jdk1.3/bin/java esc "insert into test values ({d '2000-12-01'}, 'string of\\ \' {d mmmm}', {t '12:12:12'})"
insert into test values ( '2000-12-01', 'string of\\ \' {d mmmm}', {t '12:12:12'})

Do you think we should expand it to handle the other codes like {t and {ts ?
The old routine only handles {d.

Tom.

On Tue, Aug 28, 2001 at 06:24:06PM -0700, Barry Lind wrote:
> Thomas,
>
> I can see where there might be bugs in the implementation of this
> escaping stuff. I don't think it is used very often. I believe your
> understanding of how this is supposed to work is correct.
>
> thanks,
> --Barry
>
>
> Thomas O'Dowd wrote:
> > Hi Barry,
> >
> > I found the part in the spec that talks about escape processing for
> > date and time. Thanks for pointing that out. I believe the drivers
> > implementation is wrong as it is a) changing random text data instead
> > of data of a defined format to its escape sequence and b) it can throw
> > a out of bounds exception if there is no closing }.
> >
> > Perhaps, I'll write a patch later in the day to fix this for at least
> > the date escape as that is the only one that is implemented.
> >
> > So just to clarify my understanding of what should happen...
> >
> > "SELECT a, b from c where t={d 'yyyy-mm-dd'} and a=1"
> >
> > should be changed to:
> >
> > "SELECT a, b from c where t='yyyy-mm-dd' and a=1"
> >
> > and something like
> >
> > "INSERT INTO test VALUES('don't change this {d 'yyyy-mm-dd'} as its correct. "
> >
> > should be left alone. ie, if we're in a string escape processing should
> > not be done. Right now it looks for anything with {d in the query and
> > starts changing it.
> >
> > Cheers,
> >
> > Tom.
> >
> > On Tue, Aug 28, 2001 at 12:55:19PM -0700, Barry Lind wrote:
> >
> >>Thomas,
> >>
> >>This is doing exactly what it is supposed to according to the JDBC Spec.
> >> In fact there are a bunch of other '{X }' things that the Spec
> >>defines that it should also be handling.
> >>
> >>thanks,
> >>--Barry
> >>
> >>Thomas O'Dowd wrote:
> >>
> >>>Hi all,
> >>>
> >>>The Connection.EscapeSQL() routine is broken IMHO . Actually, I'm not
> >>>sure why it is trying to fix strings starting with "{d" in the first place?
> >>>
> >>>Anyway, currently I've turned it off in the statement with
> >>>setEscapeProcessing(false)
> >>>
> >>>The problem I'm having is that "{d" appears in the data that I'm trying
> >>>to store and its not a date. So data like the following...
> >>>
> >>>.....blahhh}; {blahhh }; {docs=""};
> >>>
> >>>is turning into...
> >>>
> >>>.....blahhh}; {blahhh }; ocs="" ;
> >>> ^^ ^
> >>>
> >>>What's more is if I have something like "{d....." and there is no ending
> >>>brace, it will throw a StringIndexOutOfBoundsException as the return
> >>>value of the indexOf() looking for the closing brace will not find one
> >>>and thus setCharAt() will use an illegal index of -1 :(
> >>>
> >>>The routine is below for reference... Can anyone explain why it is trying
> >>>to do this on me in the first place. I would think escape processing would
> >>>do something a little different like watching my single quotes etc.
> >>>
> >>> public String EscapeSQL(String sql) {
> >>> //if (DEBUG) { System.out.println ("parseSQLEscapes called"); }
> >>>
> >>> // If we find a "{d", assume we have a date escape.
> >>> //
> >>> // Since the date escape syntax is very close to the
> >>> // native Postgres date format, we just remove the escape
> >>> // delimiters.
> >>> //
> >>> // This implementation could use some optimization, but it has
> >>> // worked in practice for two years of solid use.
> >>> int index = sql.indexOf("{d");
> >>> while (index != -1) {
> >>> //System.out.println ("escape found at index: " + index);
> >>> StringBuffer buf = new StringBuffer(sql);
> >>> buf.setCharAt(index, ' ');
> >>> buf.setCharAt(index + 1, ' ');
> >>> buf.setCharAt(sql.indexOf('}', index), ' ');
> >>> sql = new String(buf);
> >>> index = sql.indexOf("{d");
> >>> }
> >>> //System.out.println ("modified SQL: " + sql);
> >>> return sql;
> >>> }
> >>>
> >>>Cheers,
> >>>
> >>>Tom.
> >>>
> >>>
> >>
> >
>
>

--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs

Attachment Content-Type Size
esc.java text/plain 1.4 KB

From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Barry Lind <barry(at)xythos(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-08-30 04:09:22
Message-ID: 20010830130922.M32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hmmm, after a little more testing, I fixed a problem with backslashes.
New code attached.

Tom.

On Thu, Aug 30, 2001 at 11:46:16AM +0900, Thomas O'Dowd wrote:
> Hi all,
>
> I found some time this morning to write and test a new EscapeSQL() method.
> I didn't make a patch for the driver yet as I'd like to hear some
> comments. It's a tad longer than the original code as it only replaces
> escape codes which appear in the SQL code and not inside strings.
>
> It's attached as a separate java program which you can run to test with
> various strings. Let me know if you think it is okay. It seems to work
> with what I've tested it with.
>
> Example:
> $ /usr/local/java/jdk1.3/bin/java esc "insert into test values ({d '2000-12-01'}, 'string of\\ \' {d mmmm}', {t '12:12:12'})"
> insert into test values ( '2000-12-01', 'string of\\ \' {d mmmm}', {t '12:12:12'})
>
> Do you think we should expand it to handle the other codes like {t and {ts ?
> The old routine only handles {d.
>
> Tom.
--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs

Attachment Content-Type Size
esc.java text/plain 1.3 KB

From: Rene Pijlman <rene(at)lab(dot)applinet(dot)nl>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-09-01 21:02:47
Message-ID: 3oi2pto99etd5nfptkuflk40m576gmjgke@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Thu, 30 Aug 2001 11:46:16 +0900, Thomas O'Dowd wrote:
>I found some time this morning to write and test a new EscapeSQL()
>method. I didn't make a patch for the driver yet as I'd like to
>hear some comments.

To what extent is this implementation JDBC compliant?

The spec is in section 40.1.5 of the "JDBC API Tutorial and
Reference", 2nd edition. Its also documented on
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame11.html#7105.

Regards,
René Pijlman <rene(at)lab(dot)applinet(dot)nl>


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Rene Pijlman <rene(at)lab(dot)applinet(dot)nl>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-09-02 01:57:31
Message-ID: 20010902105731.E32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Sat, Sep 01, 2001 at 11:02:47PM +0200, Rene Pijlman wrote:
> On Thu, 30 Aug 2001 11:46:16 +0900, Thomas O'Dowd wrote:
> >I found some time this morning to write and test a new EscapeSQL()
> >method. I didn't make a patch for the driver yet as I'd like to
> >hear some comments.
>
> To what extent is this implementation JDBC compliant?
>
> The spec is in section 40.1.5 of the "JDBC API Tutorial and
> Reference", 2nd edition. Its also documented on
> http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame11.html#7105.

I think it is as compliant as what's in the current driver. It just
solves the corruption problem with some strings containing {d. If you
want to support {t and {ts then that should also be easily added. As
for supporting the other escapes sequences mentioned in section 11, I'm
not familar with the usage enough to comment on how it should be implemented.

My interest in patching this method is to solve the current data
corruption problems that I'm getting with the current implementation.

Tom.
--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: Barry Lind <barry(at)xythos(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-09-04 14:57:10
Message-ID: 200109041457.f84EvAN07965@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

> Hmmm, after a little more testing, I fixed a problem with backslashes.
> New code attached.
>
> Tom.
>
> On Thu, Aug 30, 2001 at 11:46:16AM +0900, Thomas O'Dowd wrote:
> > Hi all,
> >
> > I found some time this morning to write and test a new EscapeSQL() method.
> > I didn't make a patch for the driver yet as I'd like to hear some
> > comments. It's a tad longer than the original code as it only replaces
> > escape codes which appear in the SQL code and not inside strings.
> >
> > It's attached as a separate java program which you can run to test with
> > various strings. Let me know if you think it is okay. It seems to work
> > with what I've tested it with.
> >
> > Example:
> > $ /usr/local/java/jdk1.3/bin/java esc "insert into test values ({d '2000-12-01'}, 'string of\\ \' {d mmmm}', {t '12:12:12'})"
> > insert into test values ( '2000-12-01', 'string of\\ \' {d mmmm}', {t '12:12:12'})
> >
> > Do you think we should expand it to handle the other codes like {t and {ts ?
> > The old routine only handles {d.
> >
> > Tom.
> --
> Thomas O'Dowd. - Nooping - http://nooper.com
> tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Barry Lind <barry(at)xythos(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-09-04 15:00:41
Message-ID: 20010905000041.P32410@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi Bruce,

I guess that wasn't exactly a patch that I sent in but rather a test
program with the new routine embeded so that other people could try
it out easily.

I'll mail in the patch later. I'm a little distracted right now with
something else. For the moment just delete the patch that you added
to the unapplied list.

Cheers,

Tom.

On Tue, Sep 04, 2001 at 10:57:10AM -0400, Bruce Momjian wrote:
>
> Your patch has been added to the PostgreSQL unapplied patches list at:
>
> http://candle.pha.pa.us/cgi-bin/pgpatches
>
> I will try to apply it within the next 48 hours.
>
> > Hmmm, after a little more testing, I fixed a problem with backslashes.
> > New code attached.
> >
> > Tom.
> >
> > On Thu, Aug 30, 2001 at 11:46:16AM +0900, Thomas O'Dowd wrote:
> > > Hi all,
> > >
> > > I found some time this morning to write and test a new EscapeSQL() method.
> > > I didn't make a patch for the driver yet as I'd like to hear some
> > > comments. It's a tad longer than the original code as it only replaces
> > > escape codes which appear in the SQL code and not inside strings.
> > >
> > > It's attached as a separate java program which you can run to test with
> > > various strings. Let me know if you think it is okay. It seems to work
> > > with what I've tested it with.
> > >
> > > Example:
> > > $ /usr/local/java/jdk1.3/bin/java esc "insert into test values ({d '2000-12-01'}, 'string of\\ \' {d mmmm}', {t '12:12:12'})"
> > > insert into test values ( '2000-12-01', 'string of\\ \' {d mmmm}', {t '12:12:12'})
> > >
> > > Do you think we should expand it to handle the other codes like {t and {ts ?
> > > The old routine only handles {d.
> > >
> > > Tom.
> > --
> > Thomas O'Dowd. - Nooping - http://nooper.com
> > tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs
>
> [ Attachment, skipping... ]
>
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> > (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
> --
> Bruce Momjian | http://candle.pha.pa.us
> pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
> + If your life is a hard drive, | 830 Blythe Avenue
> + Christ can be your backup. | Drexel Hill, Pennsylvania 19026

--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: Barry Lind <barry(at)xythos(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: Escape Processing problems
Date: 2001-09-04 15:07:29
Message-ID: 200109041507.f84F7TD08538@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Patch removed at request of author. Will resubmit.

> Hmmm, after a little more testing, I fixed a problem with backslashes.
> New code attached.
>
> Tom.
>
> On Thu, Aug 30, 2001 at 11:46:16AM +0900, Thomas O'Dowd wrote:
> > Hi all,
> >
> > I found some time this morning to write and test a new EscapeSQL() method.
> > I didn't make a patch for the driver yet as I'd like to hear some
> > comments. It's a tad longer than the original code as it only replaces
> > escape codes which appear in the SQL code and not inside strings.
> >
> > It's attached as a separate java program which you can run to test with
> > various strings. Let me know if you think it is okay. It seems to work
> > with what I've tested it with.
> >
> > Example:
> > $ /usr/local/java/jdk1.3/bin/java esc "insert into test values ({d '2000-12-01'}, 'string of\\ \' {d mmmm}', {t '12:12:12'})"
> > insert into test values ( '2000-12-01', 'string of\\ \' {d mmmm}', {t '12:12:12'})
> >
> > Do you think we should expand it to handle the other codes like {t and {ts ?
> > The old routine only handles {d.
> >
> > Tom.
> --
> Thomas O'Dowd. - Nooping - http://nooper.com
> tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026


From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Patch for Statement Escape Processing problems
Date: 2001-09-10 08:27:17
Message-ID: 20010910172717.X2011@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi all,

I'm attaching a patch which fixes the corruption in strings caused
by escape processing in the SQL statement. I've tested this for a
while now and it appears to work well. Previously string data
with {d was getting corrupt as the {d was being stripped regardless
of whether it was an escape code or not.

I also added checking for time and timestamp escape processing strings
as per 11.3 in the specification. The patch is against the latest
CVS.

Cheers,

Tom.

Attachment Content-Type Size
patchfile text/plain 4.2 KB

From: "Thomas O'Dowd" <tom(at)nooper(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Patch for Statement Escape Processing problems
Date: 2001-09-14 14:38:59
Message-ID: 20010914233859.T1171@beast.uwillsee.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi all,

Wonder if anyone had a look at this patch yet? I've been using my locally
patched version for a while now and it works fine. Again just to make it
clear what it does...

- It fixes an Exception which will be thrown with the following insert.

insert into bbbb values ('xxxx{d');

- The current statement implementation also corrupts string data with '{d'
characters by removing them. This patch fixes this.

- The patch also adds support for {t and {ts escapes which are covered
in section 11.3 of the specification. Does anyone on the list use
these types of escapes???

Right now I'm mostly after fixing the corruption of strings as a lot of
my data contains the "{d" character combination and its quite annoying.

For those of you who don't know, the escapeSQL() method is called
everytime you execute a Statement or PreparedStatement if setEscapeProcessing
is set true (which is the default).

Tom.

On Mon, Sep 10, 2001 at 05:27:17PM +0900, Thomas O'Dowd wrote:
> Hi all,
>
> I'm attaching a patch which fixes the corruption in strings caused
> by escape processing in the SQL statement. I've tested this for a
> while now and it appears to work well. Previously string data
> with {d was getting corrupt as the {d was being stripped regardless
> of whether it was an escape code or not.
>
> I also added checking for time and timestamp escape processing strings
> as per 11.3 in the specification. The patch is against the latest
> CVS.
>
> Cheers,
>
> Tom.

> Index: org/postgresql/Statement.java
> ===================================================================
> RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Statement.java,v
> retrieving revision 1.2
> diff -c -r1.2 Statement.java
> *** org/postgresql/Statement.java 2001/08/10 14:42:07 1.2
> --- org/postgresql/Statement.java 2001/09/10 08:16:48
> ***************
> *** 39,44 ****
> --- 39,49 ----
>
> protected boolean escapeProcessing = true;
>
> + // Static variables for parsing SQL when escapeProcessing is true.
> + private static final short IN_SQLCODE = 0;
> + private static final short IN_STRING = 1;
> + private static final short BACKSLASH =2;
> + private static final short ESC_TIMEDATE = 3;
>
> public Statement() {
> }
> ***************
> *** 226,251 ****
> }
>
> /**
> ! * This is an attempt to implement SQL Escape clauses
> ! */
> ! protected static String escapeSQL(String sql) {
> ! // If we find a "{d", assume we have a date escape.
> ! //
> ! // Since the date escape syntax is very close to the
> ! // native Postgres date format, we just remove the escape
> ! // delimiters.
> ! //
> ! // This implementation could use some optimization, but it has
> ! // worked in practice for two years of solid use.
> ! int index = sql.indexOf("{d");
> ! while (index != -1) {
> ! StringBuffer buf = new StringBuffer(sql);
> ! buf.setCharAt(index, ' ');
> ! buf.setCharAt(index + 1, ' ');
> ! buf.setCharAt(sql.indexOf('}', index), ' ');
> ! sql = new String(buf);
> ! index = sql.indexOf("{d");
> ! }
> ! return sql;
> }
> }
> --- 231,306 ----
> }
>
> /**
> ! * Filter the SQL string of Java SQL Escape clauses.
> ! *
> ! * Currently implemented Escape clauses are those mentioned in 11.3
> ! * in the specification. Basically we look through the sql string for
> ! * {d xxx}, {t xxx} or {ts xxx} in non-string sql code. When we find
> ! * them, we just strip the escape part leaving only the xxx part.
> ! * So, something like "select * from x where d={d '2001-10-09'}" would
> ! * return "select * from x where d= '2001-10-09'".
> ! */
> ! protected static String escapeSQL(String sql)
> ! {
> ! // Since escape codes can only appear in SQL CODE, we keep track
> ! // of if we enter a string or not.
> ! StringBuffer newsql = new StringBuffer();
> ! short state = IN_SQLCODE;
> !
> ! int i = -1;
> ! int len = sql.length();
> ! while(++i < len)
> ! {
> ! char c = sql.charAt(i);
> ! switch(state)
> ! {
> ! case IN_SQLCODE:
> ! if(c == '\'') // start of a string?
> ! state = IN_STRING;
> ! else if(c == '{') // start of an escape code?
> ! if(i+1 < len)
> ! {
> ! char next = sql.charAt(i+1);
> ! if(next == 'd')
> ! {
> ! state = ESC_TIMEDATE;
> ! i++;
> ! break;
> ! }
> ! else if(next == 't')
> ! {
> ! state = ESC_TIMEDATE;
> ! i += (i+2 < len && sql.charAt(i+2) == 's') ? 2 : 1;
> ! break;
> ! }
> ! }
> ! newsql.append(c);
> ! break;
> !
> ! case IN_STRING:
> ! if(c == '\'') // end of string?
> ! state = IN_SQLCODE;
> ! else if(c == '\\') // a backslash?
> ! state = BACKSLASH;
> !
> ! newsql.append(c);
> ! break;
> !
> ! case BACKSLASH:
> ! state = IN_STRING;
> !
> ! newsql.append(c);
> ! break;
> !
> ! case ESC_TIMEDATE:
> ! if(c == '}')
> ! state = IN_SQLCODE; // end of escape code.
> ! else
> ! newsql.append(c);
> ! break;
> ! } // end switch
> ! }
> !
> ! return newsql.toString();
> }
> }

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

--
Thomas O'Dowd. - Nooping - http://nooper.com
tom(at)nooper(dot)com - Testing - http://nooper.co.jp/labs


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Patch for Statement Escape Processing problems
Date: 2001-09-15 00:16:19
Message-ID: 200109150016.f8F0GJZ21216@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

> Hi all,
>
> I'm attaching a patch which fixes the corruption in strings caused
> by escape processing in the SQL statement. I've tested this for a
> while now and it appears to work well. Previously string data
> with {d was getting corrupt as the {d was being stripped regardless
> of whether it was an escape code or not.
>
> I also added checking for time and timestamp escape processing strings
> as per 11.3 in the specification. The patch is against the latest
> CVS.
>
> Cheers,
>
> Tom.

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Thomas O'Dowd" <tom(at)nooper(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Patch for Statement Escape Processing problems
Date: 2001-09-17 15:54:52
Message-ID: 200109171554.f8HFsq510915@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Patch applied. Thanks.

> Hi all,
>
> I'm attaching a patch which fixes the corruption in strings caused
> by escape processing in the SQL statement. I've tested this for a
> while now and it appears to work well. Previously string data
> with {d was getting corrupt as the {d was being stripped regardless
> of whether it was an escape code or not.
>
> I also added checking for time and timestamp escape processing strings
> as per 11.3 in the specification. The patch is against the latest
> CVS.
>
> Cheers,
>
> Tom.

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026