Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aEdwO-00043a-Ts for pgsql-jdbc@arkaria.postgresql.org; Thu, 31 Dec 2015 14:10:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aEdwN-0005S3-9F for pgsql-jdbc@arkaria.postgresql.org; Thu, 31 Dec 2015 14:10:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aEdwM-0005Rs-BL for pgsql-jdbc@postgresql.org; Thu, 31 Dec 2015 14:10:54 +0000 Received: from smtprelay05.ispgateway.de ([80.67.31.97]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aEdwI-00066B-4i for pgsql-jdbc@postgresql.org; Thu, 31 Dec 2015 14:10:53 +0000 Received: from [88.66.27.92] (helo=Zauselmaus) by smtprelay05.ispgateway.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84) (envelope-from ) id 1aEdwF-0004PZ-Ok; Thu, 31 Dec 2015 15:10:48 +0100 From: "Markus KARG" To: "'Dave Cramer'" Cc: "'List'" References: <5684506D.4040006@labkey.com> <00be01d143a4$92c77de0$b85679a0$@eu> <00de01d143ca$389db750$a9d925f0$@eu> In-Reply-To: Subject: Re: Recent backward compatibility break in PreparedStatement.setObject() Date: Thu, 31 Dec 2015 15:10:45 +0100 Organization: Markus KARG, Staatl. gepr. Inf. Message-ID: <00f801d143d5$0afa0eb0$20ee2c10$@eu> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00F9_01D143DD.6CBE76B0" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdFDzqm1OXLBEtILT8+2aZj0vPU9DgABkOhg Content-Language: de X-AVK-Virus-Check: AVA 25.4965;8ADD39BE X-AVK-Spam-Check: 1; str=0001.0A0C0205.56853765.00FB,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0; F1206 X-Df-Sender: bWFya3VzQGhlYWRjcmFzaGluZy5ldQ== X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org This is a multi-part message in MIME format. ------=_NextPart_000_00F9_01D143DD.6CBE76B0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Never mind. :-) -Markus =20 From: davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of = Dave Cramer Sent: Donnerstag, 31. Dezember 2015 14:25 To: Markus KARG Cc: List Subject: Re: [JDBC] Recent backward compatibility break in = PreparedStatement.setObject() =20 Apologies, you are correct I should have announced it. Dave Cramer davec@postgresintl.com www.postgresintl.com =20 On 31 December 2015 at 07:53, Markus KARG = wrote: Thanks, but as I also developed the fix as announced this morning, I now = spent time for nothing! Would be good if also the project lead *first* = files a bug report and assigns to itself. :-( =20 From: davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of = Dave Cramer Sent: Donnerstag, 31. Dezember 2015 12:32 To: Markus KARG Cc: Adam Rauch; List Subject: Re: [JDBC] Recent backward compatibility break in = PreparedStatement.setObject() =20 I put a PR in already https://github.com/pgjdbc/pgjdbc/pull/480 Dave Cramer davec@postgresintl.com www.postgresintl.com =20 On 31 December 2015 at 03:23, Markus KARG = wrote: I'm the original contributor of that changeset. This is simply a bug. = I'll fix it later today. Thanks for reporting! :-) -Markus =20 From: pgsql-jdbc-owner@postgresql.org = [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Dave Cramer Sent: Mittwoch, 30. Dezember 2015 22:55 To: Adam Rauch Cc: List Subject: Re: [JDBC] Recent backward compatibility break in = PreparedStatement.setObject() =20 No, this was not intentional. =20 Thanks for the report! Dave Cramer davec@postgresintl.com www.postgresintl.com =20 On 30 December 2015 at 16:45, Adam Rauch wrote: The PostgreSQL JDBC driver recently changed PreparedStatement behavior = with calls such as setObject(index, value, Types.VARCHAR). Previously, = the driver would call value.toString() before binding all VARCHAR = values... meaning any object could be passed as "value." In recent = updates (e.g., 9.4.1207), most non-String values now result in an = exception: Exception in thread "main" org.postgresql.util.PSQLException: Cannot = convert an instance of XXX to type String at = org.postgresql.jdbc.PgStatement.cannotCastException(PgStatement.java:1813= ) at = org.postgresql.jdbc.PgStatement.cannotCastException(PgStatement.java:1809= ) at = org.postgresql.jdbc.PgStatement.castToString(PgStatement.java:1805) at = org.postgresql.jdbc.PgStatement.setObject(PgStatement.java:1540) at = org.postgresql.jdbc.PgStatement.setObject(PgStatement.java:1818) at PGTest.main(PGTest.java:25) This seems to have broken during the refactor to support binary transfer = for setObject(), https://github.com/pgjdbc/pgjdbc/issues/328. Was the = behavior change intentional? If so, it should probably be documented = (e.g., I didn't see any mention in the change log). If not, I'd suggest = going back to calling value.toString() for all types. I'm sure ours is = not the only application that relies on this long-standing (>10 years) = PostgreSQL JDBC behavior. FWIW, other JDBC drivers call toString() in = this situation. Here's a contrived example that demonstrates the behavior change. This = code snippet runs fine in 1201 but fails with the exception above in = 1207. Object param =3D new Object() {public String toString() {return = "tables";}}; =20 try (PreparedStatement stmt =3D conn.prepareStatement("SELECT * FROM = information_schema.tables WHERE table_name =3D ?")) { stmt.setObject(1, param, Types.VARCHAR); =20 try (ResultSet rs =3D stmt.executeQuery()) { while (rs.next()) System.out.println(rs.getString(1)); } } Thanks, Adam =20 =20 =20 ------=_NextPart_000_00F9_01D143DD.6CBE76B0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Never mind. :-)

-Markus

 

From:= = davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of = Dave Cramer
Sent: Donnerstag, 31. Dezember 2015 = 14:25
To: Markus KARG
Cc: List
Subject: = Re: [JDBC] Recent backward compatibility break in = PreparedStatement.setObject()

 

Apologies, you are correct I should have announced = it.


 

On 31 December 2015 at 07:53, Markus KARG <markus@headcrashing.eu> = wrote:

Thanks, but as I also developed the fix as announced this morning, I = now spent time for nothing! Would be good if also the project lead = *first* files a bug report and assigns to itself. = :-(

 

From:= davecramer@gmail.com [mailto:davecramer@gmail.com] On Behalf Of Dave = Cramer
Sent: Donnerstag, 31. Dezember 2015 12:32
To: = Markus KARG
Cc: Adam Rauch; = List


Subject: Re: [JDBC] Recent backward = compatibility break in = PreparedStatement.setObject()

<= p class=3DMsoNormal = style=3D'mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <= /o:p>


 <= /o:p>

On 31 = December 2015 at 03:23, Markus KARG <markus@headcrashing.eu> = wrote:

I'm the original contributor of that changeset. This is simply a bug. = I'll fix it later today. Thanks for reporting! = :-)

-Markus

 

From:= pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of = Dave Cramer
Sent: Mittwoch, 30. Dezember 2015 = 22:55
To: Adam Rauch
Cc: List
Subject: Re: = [JDBC] Recent backward compatibility break in = PreparedStatement.setObject()

 <= /o:p>

No, this = was not intentional.

 <= /o:p>

Thanks for = the report!


 <= /o:p>

On 30 = December 2015 at 16:45, Adam Rauch <adam@labkey.com> wrote:

The PostgreSQL = JDBC driver recently changed PreparedStatement behavior with calls such = as setObject(index, value, Types.VARCHAR). Previously, the driver would = call value.toString() before binding all VARCHAR values... meaning any = object could be passed as "value." In recent updates (e.g., = 9.4.1207), most non-String values now result in an = exception:

    Exception in thread = "main" org.postgresql.util.PSQLException: Cannot convert an = instance of XXX to type String
        at = org.postgresql.jdbc.PgStatement.cannotCastException(PgStatement.java:1813= )
        at = org.postgresql.jdbc.PgStatement.cannotCastException(PgStatement.java:1809= )
        at = org.postgresql.jdbc.PgStatement.castToString(PgStatement.java:1805)<= br>        at = org.postgresql.jdbc.PgStatement.setObject(PgStatement.java:1540)
=         at = org.postgresql.jdbc.PgStatement.setObject(PgStatement.java:1818)
=         at = PGTest.main(PGTest.java:25)


This seems to have broken = during the refactor to support binary transfer for setObject(), https://github.com/pgjdbc/pgjdbc/issues/328. Was = the behavior change intentional? If so, it should probably be documented = (e.g., I didn't see any mention in the change log). If not, I'd suggest = going back to calling value.toString() for all types. I'm sure ours is = not the only application that relies on this long-standing (>10 = years) PostgreSQL JDBC behavior. FWIW, other JDBC drivers call = toString() in this situation.

Here's a contrived example that = demonstrates the behavior change. This code snippet runs fine in 1201 = but fails with the exception above in 1207.

    Object param =
=3D new =
Object() =
{public =
String toString() =
{return =
"tables";}};
 
    try =
(PreparedStatement stmt =3D =
conn.prepareStatement("SELECT * FROM information_schema.tables =
WHERE table_name =3D ?"))
    =
{
      =
;  stmt.setObject(1, param, Types.VARCHAR);
 
        try =
(ResultSet rs =3D =
stmt.executeQuery())
      =
;  {
      =
;      while =
(rs.next())
=
      =
;          =
System.out.println(rs.getString(1));
  =
      }
    =
}


Thanks,<= br>Adam

 <= /o:p>

 <= /o:p>

 

------=_NextPart_000_00F9_01D143DD.6CBE76B0--