> From: mhm@austin.ibm.com
>
> Ok, question time. How do we expect the DBI::DBD interfaces to work
> when it comes to columns returning null?
>
Instances of NULLS are represented on input and output as undefs. Period.
> $sth->execute();
> while (@row = $sth->fetchrow) {
> ...
> }
>
> If the $stmt requests only one column from the table
> and the column can contain NULLs then it is possible to return only
> part of the data.
This is a perl bug discovered recently by Michael Peppler working on Sybase.
I CC'd a reply to perlbug@perl.com but I think it bounced. I'll CC this.
> If $stmt requests more than one column and the first
> column requested can contain NULLs, we break again.
>
Not quite. It breaks if *all* the columns are nulls. Here's a test case:
sub undef_a { (undef, undef, 1, undef) }
sub undef_b { (undef, undef, undef, undef) }
sub undef_c { (undef) }
(@ary = undef_a()) ? print "ok\n" : print "not ok\n";
(@ary = undef_b()) ? print "ok\n" : print "not ok\n";
(@ary = undef_c()) ? print "ok\n" : print "not ok\n";
It prints:
ok
not ok
not ok
This *is* a serious problem for database work!
> I guess, my point is that we need some method of returning something
> other than a Nullsv or sv_undef and giving the enduser a method of
> checking the null indicator from the fbh struct.
>
Nope. Perl needs fixing! This really needs to be fixed before 5.002.
(Note: _never_ return Nullsv on the stack, always use &sv_undef.)
In the meantime you can use the alternative (and faster) $sth->fetch
method upon which fetchrow is implemented:
while($aryref = $sth->fetch) {
.... code using @$aryref or $aryref->[n] ...
}
but this won't help people who need to stick to the Oraperl emulation interface.
Tim.
>
> Ok, question time. How do we expect the DBI::DBD interfaces to work
> when it comes to columns returning null?
>
Instances of NULLS are represented on input and output as undefs. Period.
> $sth->execute();
> while (@row = $sth->fetchrow) {
> ...
> }
>
> If the $stmt requests only one column from the table
> and the column can contain NULLs then it is possible to return only
> part of the data.
This is a perl bug discovered recently by Michael Peppler working on Sybase.
I CC'd a reply to perlbug@perl.com but I think it bounced. I'll CC this.
> If $stmt requests more than one column and the first
> column requested can contain NULLs, we break again.
>
Not quite. It breaks if *all* the columns are nulls. Here's a test case:
sub undef_a { (undef, undef, 1, undef) }
sub undef_b { (undef, undef, undef, undef) }
sub undef_c { (undef) }
(@ary = undef_a()) ? print "ok\n" : print "not ok\n";
(@ary = undef_b()) ? print "ok\n" : print "not ok\n";
(@ary = undef_c()) ? print "ok\n" : print "not ok\n";
It prints:
ok
not ok
not ok
This *is* a serious problem for database work!
> I guess, my point is that we need some method of returning something
> other than a Nullsv or sv_undef and giving the enduser a method of
> checking the null indicator from the fbh struct.
>
Nope. Perl needs fixing! This really needs to be fixed before 5.002.
(Note: _never_ return Nullsv on the stack, always use &sv_undef.)
In the meantime you can use the alternative (and faster) $sth->fetch
method upon which fetchrow is implemented:
while($aryref = $sth->fetch) {
.... code using @$aryref or $aryref->[n] ...
}
but this won't help people who need to stick to the Oraperl emulation interface.
Tim.