Strange perl problem
Posted in 2003
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Versions, Editions & End-of-Life
perl 5.6.0 INFORMIX-ESQL Version 9.16.UC1 IDS 9.21.UC4 Solaris 2.6 I am not that proficient in perl DBD. Here is an excerpt of a routine which checks whether a branch exists or not. All it does is a count for that branch name. Since branch name is unique index, the count should always return 0 or 1. What I find strange is that this function returns 1 correctly when a branch already exists, but branch-not-exists is returned as 0.00000E+00. Why is 0 returned in this format, but not 1. This doesn't break my code as I check for 1 only, but this is something which I want to learn for future use. In fact I checked out that if my code checks for 0 also, it works fine. But the E format for showing 0 is bit puzzling. Ravi sub check_branch_exists() { $tth = $tdbh->prepare("select count(*) from branch where bname = \\"$bname\\""); $tth->execute or die "Can't execute SQL statement: $DBI::errstr\\n" ; my @count_total = $tth->fetchrow_array() ; my $branch_exists = $count_total[0] ; return $branch_exists ; }
rkusenet wrote: > perl 5.6.0 > INFORMIX-ESQL Version 9.16.UC1 > IDS 9.21.UC4 > Solaris 2.6 Ouch - please upgrade! > I am not that proficient in perl DBD. > Here is an excerpt of a routine which checks whether a branch > exists or not. All it does is a count for that branch name. Since > branch name is unique index, the count should always return 0 or 1. > > What I find strange is that this function returns 1 correctly when a branch > already exists, but branch-not-exists is returned as 0.00000E+00. Why is 0 > returned in this format, but not 1. A weird piece of Perl-ism. And DBD::Informix in old enough versions... There is a place in DBI where the correct return value for zero is 0E0 or equivalent - on the grounds that it compares true but zero, whereas if the returned value was 0, the value would compare false and zero. However, IIRC, that's the $sth->rows() function, not this code. > This doesn't break my code as I check for 1 only, but this is > something which I want to learn for future use. In fact I checked out that > if my code checks for 0 also, it works fine. But the E format for showing > 0 is bit puzzling. > > Ravi > > > sub check_branch_exists() > { > $tth = $tdbh->prepare("select count(*) from branch where bname = \\"$bname\\""); > $tth->execute or die "Can't execute SQL statement: $DBI::errstr\\n" ; > my @count_total = $tth->fetchrow_array() ; > my $branch_exists = $count_total[0] ; > return $branch_exists ; > } If you poked at the $tth->{ix_NativeTypeName} value, you'd probably find that the return value from COUNT(*) was a DECIMAL. Your version of DBD::Informix is old enough to format that somewhat weirdly (I fixed that a couple of years ago, IIRC - hmmm, the ChangeLog suggests it was March 2000 that I made the code change but the rest of the world didn't get to see it for quite a while). One caveat: don't upgrade DBD::Informix without also upgrading (a) DBI and (b) ESQL/C. I don't support ESQL/C 9.16 any more. I'm not aware of anything that will fail, but ... Also, perl 5.6.0 is not supported by the most recent versions of DBI - you should be upgrading to 5.6.1 or (better) 5.8.x (where the current x is 2). -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/