|
|
sybperl-l Archive
Up Prev Next
From: Jamie Belanger <jamie_belanger at globalcrossing dot com>
Subject: NULL values from a table
Date: Jan 26 2000 4:11PM
Following is a portion of a script I wrote which counts the number of active
calling cards for each of our accounts. However, I run into a problem when
the account HAS no active cards (ie, when the select count(*) returns what
looks like 0). What happens is that the next time the while loop executes, I
get an error stating that I can't proceed until all fetchable results are
processed. Here's an example of my error output:
______________________________________
Beginning count on t618ESC
Tue Jan 25 12:13:42 CST 2000
Completed t618ESC
Tue Jan 25 12:13:43 CST 2000
(27 of 58) - sleeping for 30s
Beginning count on t620ESC
Tue Jan 25 12:14:13 CST 2000
Open Client Message: (In msg_cb)
Message number: LAYER = (1) ORIGIN = (1)SEVERITY = (1) NUMBER = (163)
Message String: ct_results(): user api layer: external error: This routine
cannot be called until all fetchable results have been completely processed.
Completed t620ESC
Tue Jan 25 12:14:13 CST 2000
(28 of 58) - sleeping for 30s
Beginning count on t621ESC
Tue Jan 25 12:14:43 CST 2000
Open Client Message: (In msg_cb)
Message number: LAYER = (1) ORIGIN = (1)SEVERITY = (1) NUMBER = (16)
Message String: ct_command(): user api layer: external error: This routine
cannot be called while results are pending for a command that has been sent
to the server.
_______________________________________
I believe the problem is that the 0 is a null, rather than an actual value.
However, I can't simply exclude all accounts which have no active cards from
my script, because at any time cards may be added to these accounts. That's
hard-coding something that I don't really wish to hard code... I'm rather
new to sybperl (about a month now), so I'm not sure of what kind of
condition I need to place in my loop that doesn't run into the problem with
the null value. Following is the portion of my script which is experiencing
the difficulties:
_______________________________________
#Cycle through the accounts and query each one for the number of active
cards
for ( $i=0; $i<=$#storage; $i++)
{
$ESC = $storage[$i]; #puts the account number in the $ESC
variable
chomp($ESC); #gets rid of the newline character
print "Beginning count on $ESC\n";
print `date`;
#SQL statement that counts the active cards in a given account
$SQL2 = "select count(*) from $ESC where uchCardStatus = 0";
#Execute the above statement
$X->ct_execute($SQL2);
#Grabs the number of active cards and places it in the $count
variable
while ( $X->ct_results($restype) == CS_SUCCEED)
{
next if( !$X->ct_fetchable($restype));
while ($tally = $X->ct_fetch)
{
$count = "$tally\n";
}
}
print ACTIVE "$ESC" . " $count\n"; #print information to the file
$current = $count; #variable to store current card
count
$total = $total + $current; #add up the active cards
print "Completed $ESC\n";
______________________________________________
As a side thought, is there a better way to grab the data than ct_fetch?
That was the most efficient manner that I could find, but as I'm still
stumbling through the initial phases of writing with sybperl, I could very
well be mistaken! I have leaning towers of perl books around my desk at all
times. :)
Jamie Belanger
Sys Admin, Global Crossing
(319) 298-1489 or ext. 489
|