X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C0F2D329ECC for ; Fri, 8 Oct 2004 04:32:50 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52214-09 for ; Fri, 8 Oct 2004 03:32:47 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id B4D6B329EC2 for ; Fri, 8 Oct 2004 04:32:47 +0100 (BST) Received: from flood.opencloud.co.nz ([192.168.0.31]) by yass.opencloud.co.nz with esmtp (Exim 3.35 #1 (Debian)) id 1CFlUm-0006ZR-00 for ; Fri, 08 Oct 2004 16:32:40 +1300 Message-ID: <41660A56.5000107@opencloud.com> Date: Fri, 08 Oct 2004 16:32:38 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "pgsql-jdbc@postgresql.org" Subject: tightening up on use of oid 0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=TO_ADDRESS_EQ_REAL X-Spam-Level: X-Archive-Number: 200410/60 X-Sequence-Number: 11165 I am currently cleaning up a few places where OID 0 could get used as a parameter type (causing the backend to try to infer a type). For example, this occurs when setObject() is passed an object that it can't classify (not any of Integer, Boolean, PGobject, etc), or when calling setObject() with a non-PGobject and Types.OTHER. I think this is a bad idea: we do not have any mechanism in place to check that the type actually matches the expected type. It also seems quite fragile to rely on this behaviour when everything else in JDBC is fairly strongly typed. Another place I am less sure about is setNull(x, Types.OTHER); this passes the NULL with type OID 0. Without this, there is no other way to set a nonstandard-typed parameter to null. I think this is still problematic. Consider the case where you have two functions: foo(line) foo(box) Executing "SELECT foo(?)" via PreparedStatement will work fine if you pass a non-null PGline or PGbox argument to setObject, but if you try to setNull() then you will get ambiguity between the two functions at execution time. I can't see a way to fix this without a postgresql extension of some sort. Options I can think of are: 1) PGStatement.setNull(int parameterIndex,String databaseType): sets parameter to null with the given type. 2) PGStatement.setTypeHint(int parameterIndex,String databaseType): sets parameter's type, only, to the given type; this is then used by later calls to setNull(). 3) PGConnection.addDataType(String type, Class klass, int sqlType): register a new java.sql.Types value along with the type handler. (3) seems like the least intrusive approach, but it requires that extension types somehow decide on a unique Types value. I'm not sure if this is practical. -O