Re: Problem asking columns allowing NULL values - Mailing list pgsql-jdbc

From .
Subject Re: Problem asking columns allowing NULL values
Date
Msg-id 20030410211314.76e9ecc7.alzina@inicia.es
Whole thread Raw
In response to Re: Problem asking columns allowing NULL values  (Dave Cramer <Dave@micro-automation.net>)
Responses Re: Problem asking columns allowing NULL values
Re: Problem asking columns allowing NULL values
List pgsql-jdbc
> Can you send me a small test program to demonstrate the problem?
>
> Dave
> On Tue, 2003-04-08 at 13:23, Manel de la Rosa wrote:
> > Hello,
> > I'm trying to ask a PostgreSQL server, using its JDBC driver, if the
> > columns of a table allow NULL values. To do so, I look at the value of the
> > field columnNullable (class ResultSetMetaData). Simply put, if I have a
> > ResultSet"rs" filled with rows from a query, I do the following:
> >
> >
> >
> > ResultSetMetaData rsmeta = rs.getMetaData();
> >
> >    if (rsmeta.columnNullable == 1)
> >     System.out.printl("null values allowed");
> >    else
> >     System.out.printl("null values NOT allowed");
> >
> >
> >
> > The result says that *all* columns allow NULL values, although I've defined
> > several of them with the clause "NOT NULL" (I've checked that this columns
> > does really not allow NULL values, trying INSERT statements with psql).
> >
> > I'm using the last stable release of the JDBC driver. Somebody else have
> > suffered the same problem? Or I'm doing something wrong? I'd be very
> > grateful if somebody could help me.
> >
>

Oopss!!!
Sorry, I was doing wrong! I was looking at the value of rsmeta.columnNullable,
a *static* variable, instead of calling to
ResultSetMetaData.isNullable(column). My fault.

But now that I'm doing right, surprise: *all* columns are found as
"columnNullableUnknown" by the JDBC driver. Looking at old mails of this list,
I've found a 2001 message describing the same problem, proposing a temporal
patch and saying this:

"This method is currently unimplemented and always returns
ResultSetMetaData.columnNullable. This is obviously incorrect
when a column is defined with NOT NULL or PRIMARY KEY. And we
have to think of check constraints, views, functions etc.

This patch simply changes the return value to
ResultSetMetaData.columnNullableUnknown. This is until someone
comes up with a real implementation of course."

I'll apreciate if somebody could tell me if someone are working on this. If
not, well, I'm not a Java guru, but perhaps I could help.

Thanks.


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: RES: Problems retrieving data from bytea field
Next
From: Peter Royal
Date:
Subject: Re: Problem asking columns allowing NULL values