[Bioperl-l] DB2 driver for BioPerl
Florian Mittag
florian.mittag at uni-tuebingen.de
Thu Aug 6 09:38:38 UTC 2009
Hi!
I just noticed, that we didn't solve this problem completely.
On Wednesday, 15. July 2009 15:00, Florian Mittag wrote:
> > Well, it is like this with version 9.5 of DB2 Express-C:
> >
> > SELECT NULL FROM bioentry;
> >
> > yields:
> > SQL0206N "NULL" is not valid in the context where it is used.
> > SQLSTATE=42703 SQLCODE=-206
> >
> > But if I do:
> >
> > SELECT cast(NULL AS VARCHAR(255)) FROM bioentry;
> >
> > [...]
> >
> > It ran fine without the NULL column, but that isn't necessarily a sign of
> > correctness. My problem was that (as stated above) the old version of DB2
> > requires you to cast the NULL value to a data type, which I wasn't able
> > to determine from the code. With the new version, it should work, so I'll
> > have to rerun my tests again and see if the problem is still there.
>
> You convinced me that the NULL column is supposed to be there, so I found
> another workaround around line 1273 in BaseDriver.pm:
>
> if((! $attr) || (! $entitymap->{$tbl}) ||
> $dont_select_attrs->{$tbl .".". $attr}) {
> #push(@attrs, "NULL");
> push(@attrs, "cast(NULL as VARCHAR(255))");
> } else {
>
> Since I don't know how to determine the datatype of the column that is set
> to NULL, I simply chose VARCHAR and tested it. And it worked! (BTW: The
> column set to NULL is named "rank" in the case below.)
Although this solution works, it is not the best, because it breaks
compatibility with all other database types, e.g., MySQL. Is there a way to
change the "NULL" to "cast(NULL as VARCHAR(255))" only when the driver is
DB2?
- Florian
More information about the Bioperl-l
mailing list