pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: tightening up on use of oid 0
Date: Fri, 08 Oct 2004 16:32:38 +1300
Message-ID: <41660A56.5000107@opencloud.com> (raw)

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



view thread (20+ messages)  latest in thread

Message-ID: <41660A56.5000107@opencloud.com>
Permalink:  ../41660A56.5000107@opencloud.com/
Also on:    postgresql.org/message-id/41660A56.5000107@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com
  Subject: Re: tightening up on use of oid 0
  In-Reply-To: <41660A56.5000107@opencloud.com>
  References: <41660A56.5000107@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox