APM: Null fields and 100% porcessor

Goldilox Goldilox at teachnet.edb.utexas.edu
Tue Apr 1 15:27:59 CST 2003


Thanks for all the response - I had sent an email (I thought) to this group and
got no response about the NULL problem

what's the difference between austin-pm at pm.org and austin at mail.pm.org?

anyway I'll start over:

>> Microsoft SQL7 database. I have various cells in the database 
>> that are set to
>> 
>> NULL
>> 
>> (I had to spend a lot of time tracking them down to find what 
>> was causing the
>> warnings)

use CGI;my $cg=new CGI;
use DBI;
use DBD::ODBC;

my $dbh = DBI->connect('dbi:ODBC:HydrometSQL','user','pass') || die "Database
connection not made: $DBI::errstr";

my $sql = qq{select sensordef.sensor_number, site.site_name from (sensordef
INNER JOIN site ON sensordef.site_id = site.site_id) where
sensordef.sensor_number > 99999 and site.in_service <> 0 and
sensordef.in_service <> 0 order by site.site_number};

my $newsth = $dbh->prepare( $sql ) ||die "Couldn't prepare statement:
$DBI::errstr";

>
>> 
>> This one works the best so far, but still gives an 
>> uninitialized variable
>> warning when a NULL is encountered:
>> 
>> while(my @newdata = $newsth->fetchrow_array()){
>> print "Before: $newdata[1] - $newdata[2]\n";
>> $newdata[1] = "N/A" if $newdata[1] eq "";
>> $dataone=$newdata[1];
>> $newdata[2] = "N/A" if $newdata[2] eq "";
>> $datatwo=$newdata[2];
>> $newdata[3] = "N/A" if $newdata[3] eq "";
>> print "After: $newdata[1] - $newdata[2] - $newdata[3]\n";
>> $datathree=$newdata[3];
>> $htmldata=$htmldata.qq~<tr><td>$dataone</td><td 
>> align="right">$datatwo</td><td
>> align="right">$datathree</td></tr>~;
>> }
>> 
>> I have tried:
>> 
>> 1)
>> $newdata[3] = "N/A" if undef $newdata[3];
>> 
>> 
>> 2)
>> $newdata[3] = "N/A" if $newdata[3] eq "NULL";#(OK, this was 
>> dumb - but I wanted
>> to say I tried it)
>> 
>> 
>> 3)
>> and I have tried: $newsth->fetchall_arrayref (with 
>> appropriate trappings)
>> 
>> 
>> No matter what, I get an uninitialized variable warning 
>> whenever there is a
>> database cell designated as NULL. I need the script to run 
>> without these
>> warnings appearing.
>> (the reason I need the warnings to disappear is: I want to 
>> use Perl for
>> database needs, currently some Frontpage generated ASP code 
>> is being used, and
>> the error handling of the ASP detects these NULL fields - I 
>> need Perl to run
>> just as cleanly because the folks who maintain the ASP code 
>> don't want me using
>> Perl since they only know ASP - it's a weird situation, I 
>> know, but I want to
>> show Perl can do the job just as cleanly, but I haven't been 
>> able to do that
>> yet)
>> 
>> Help?
>> 
>> Rhett

I guess I'm hearing that the Perl script will let go of the processor as much
as it needs when web server requests come in. I'll be going with that and
trying it for now anyway.

I hope I'm not being too confusing here.

Rhett




More information about the Austin mailing list