Re: PreparedStatement.toString() creates valid SQL; was: Q: use setObject also for int or string

From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Enke <michael(dot)enke(at)wincor-nixdorf(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement.toString() creates valid SQL; was: Q: use setObject also for int or string
Date: 2008-09-21 23:22:59
Message-ID: Pine.BSO.4.64.0809211910030.27954@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Sun, 21 Sep 2008, Michael Enke wrote:

> I did this and it would be great if you could have a look into the
> attached patch files and make comments.
>
> It has to set standard_conforming_strings to false
> in any case to create valid sql:
> If I use setString(1, "a\\b");
> the real stored characters are 'a','\','b'.
> If I would use standard_conforming_strings=true
> the output would be "a\b"
> but with set to false the output is "a\\b" which is the correct one.

One of the backslashes is used for Java's escaping, so the real data does
only have one backslash which is the correct behavior for
standard_conforming_strings. Also note that E'' syntax is only supported
on 8.1 and later servers, so it can't be used unconditionally.

> I did not understand what you mean with InputStream.

See the attached test case.

Also note that the String "NULL" should be 'NULL', not plain NULL.

Kris Jurka

Attachment Content-Type Size
PrintQuery.java text/plain 770 bytes

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Michael Enke 2008-09-22 19:10:56 Re: PreparedStatement.toString() creates valid SQL; was: Q: use setObject also for int or string
Previous Message Michael Enke 2008-09-21 19:32:05 Re: PreparedStatement.toString() creates valid SQL; was: Q: use setObject also for int or string