X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id AF1F79FA65C for ; Tue, 25 Jul 2006 15:57:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 81753-04 for ; Tue, 25 Jul 2006 15:57:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with SMTP id 980469FAE4E for ; Tue, 25 Jul 2006 15:57:24 -0300 (ADT) Received: (qmail 31559 invoked by uid 1112); 25 Jul 2006 18:57:23 -0000 Date: Tue, 25 Jul 2006 13:57:23 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary2.csoft.net To: Akira Sato cc: pgsql-jdbc@postgresql.org Subject: Re: PreparedStatement clearParameters and setTimestamp In-Reply-To: <44C5771E.4090103@oss.ntt.co.jp> Message-ID: References: <44C5771E.4090103@oss.ntt.co.jp> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-346975018-1153853843=:1253" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.033 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200607/83 X-Sequence-Number: 15509 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-346975018-1153853843=:1253 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Tue, 25 Jul 2006, Akira Sato wrote: > This reply is about the following threads. > http://archives.postgresql.org/pgsql-jdbc/2006-02/msg00156.php > > With case of setTimestamp(), it seem to always do "Parse". > (setDate() and setTime() too) > > create table test(id int, tm timestamp); > > int n = 10; > Timestamp tm = new Timestamp(System.currentTimeMillis()); > PreparedStatement pst = conn.prepareStatement("INSERT INTO test(id, tm) > VALUES (?, ?)"); > for(int i=0; i< n; i++){ > pst.clearParameters(); > pst.setInt(1, i); > pst.setTimestamp(2, tm); > pst.executeUpdate(); > } > pst.close() > The above problem has nothing to do with the clearParameters call. You can see this by removing it from the above test and noting that it still parses it every time through. The real problem has to do with using oid zero for the date+time datatypes. When determining if a statement must be reparsed the driver checks that the parameters it currently has match with the previous execution. This comparison is being done with the values returned from the server for the previous execution, not the values sent to the server. So you parse once with oid 0 and it comes back with the oid of the resolved type, say 1184 for timestamptz. The next time through you again have oid 0 from setTimestamp, and it compares 0 == 1184? and it determines they don't match and it must be reparsed. The attached patch fixes your test case for me, but I haven't applied it yet as I'd like to do some more testing. It doesn't allows oid 0 to match any type the server resolves. Kris Jurka --0-346975018-1153853843=:1253 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=dont-reparse-unspecified.patch Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: Content-Disposition: attachment; filename=dont-reparse-unspecified.patch SW5kZXg6IG9yZy9wb3N0Z3Jlc3FsL2NvcmUvdjMvU2ltcGxlUXVlcnkuamF2 YQ0KPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PQ0KUkNTIGZpbGU6IC91c3IvbG9j YWwvY3Zzcm9vdC9wZ2pkYmMvcGdqZGJjL29yZy9wb3N0Z3Jlc3FsL2NvcmUv djMvU2ltcGxlUXVlcnkuamF2YSx2DQpyZXRyaWV2aW5nIHJldmlzaW9uIDEu MTANCmRpZmYgLWMgLXIxLjEwIFNpbXBsZVF1ZXJ5LmphdmENCioqKiBvcmcv cG9zdGdyZXNxbC9jb3JlL3YzL1NpbXBsZVF1ZXJ5LmphdmEJMjYgQXByIDIw MDYgMjA6MDY6NTMgLTAwMDAJMS4xMA0KLS0tIG9yZy9wb3N0Z3Jlc3FsL2Nv cmUvdjMvU2ltcGxlUXVlcnkuamF2YQkyNSBKdWwgMjAwNiAxODo1NTo0MSAt MDAwMA0KKioqKioqKioqKioqKioqDQoqKiogOTEsOTcgKioqKg0KICANCiAg ICAgICAgICAvLyBDaGVjayBmb3IgY29tcGF0aWJsZSB0eXBlcy4NCiAgICAg ICAgICBmb3IgKGludCBpID0gMDsgaSA8IHBhcmFtVHlwZXMubGVuZ3RoOyAr K2kpDQohICAgICAgICAgICAgIGlmIChwYXJhbVR5cGVzW2ldICE9IHByZXBh cmVkVHlwZXNbaV0pDQogICAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7 DQogIA0KICAgICAgICAgIHJldHVybiB0cnVlOw0KLS0tIDkxLDk3IC0tLS0N CiAgDQogICAgICAgICAgLy8gQ2hlY2sgZm9yIGNvbXBhdGlibGUgdHlwZXMu DQogICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBwYXJhbVR5cGVzLmxl bmd0aDsgKytpKQ0KISAgICAgICAgICAgICBpZiAocGFyYW1UeXBlc1tpXSAh PSAwICYmIHBhcmFtVHlwZXNbaV0gIT0gcHJlcGFyZWRUeXBlc1tpXSkNCiAg ICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsNCiAgDQogICAgICAgICAg cmV0dXJuIHRydWU7DQo= --0-346975018-1153853843=:1253--