print after while loop not executing.

Why is the print statement after this while loop never being reached and how do I fix the problem:

$cursor = $db->prepare($sql) or die "Unable to Execute SQL: $DBI::errstr";
$cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
while (@row = $cursor->fetchrow_array or die "<br>FETCH DIED:<br> $DBI::errstr")
{
   print "<Strong>Row $countit</STRONG><br>\n";
   print "@row<br>\n";
   $countit++;
}
print "REPORT COMPLETE<br>";


Thanks
Nina
ngerdaAsked:
Who is Participating?
 
b2piConnect With a Mentor Commented:
No, you need to call finish on the handles....  i.e.

$db->finish;
$db->disconnect;

0
 
ngerdaAuthor Commented:
Adjusted points to 155
0
 
b2piCommented:
Because when you're out of data, @row comes back as undefined, and thus you die.

fetchrow is listed as being of max speed, with no error checking, etc.  Since you know that the sql executed properly (from the line above the while), just drop that check, and shove out a different message if you have no rows... i.e.

$cursor->execute or die "Unable to execute SQL: $DBI:errstr";
$countit = 0;
while (@row = $cursor->fetchrow_array or die "<br>FETCH DIED:<br> $DBI::errstr")
{
       print "<Strong>Row $countit</STRONG><br>\n";
       print "@row<br>\n";
       $countit++;
}
if ($countit) {
  print "REPORT COMPLETE<br>";
} else {
  print "NO ROWS FOUND<br>";
}
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
ngerdaAuthor Commented:
Now I get this error after the last row is processed in the loop.  How do I fix it so your solution works?

FETCH DIED: at W:\Inetpub\CERPS\cgi-bin\WEBTEST.pl line 36. Database handle destroyed without explicit
disconnect.
0
 
b2piCommented:
1.) What's at line 36?
2.) I screwed up when I posted that code.... the while line should have been

while(@row = $cursor->fetchrow_array)
{
    ....
0
 
ngerdaAuthor Commented:
I did that and now get the followING error right before my ClosURE processing below;

ERROR:
dbih_clearcom (h 0xb5e49c, com 0x824e90): FLAGS 0x111: COMSET Warn PrintError TYPE 3 PARENT DBI::db=HASH(0xb5eb94) KIDS 0 (0 active) IMP_DATA undef in 'DBD::Oracle::st' NUM_OF_FIELDS 41 NUM_OF_PARAMS 0

CLOSURE PROCESSING:
print "REPORT COMPLETE<BR>";  *** THIS IS THE LAST LINE TO PRINT OUT
print "</CENTER>\n";
print "</BODY>\n";
print "</HTML>\n";
$db->disconnect() or die "Unable to disconnect : $DBI::errstr";  
$db->Close();
}

SUB ROUTINES FOLLOW.....
0
 
b2piCommented:
How many new questions can you ask?

You're not giving enough information.... However, looking at your code, what is

$db->Close();

That's not a DBI call... (nor a DBD call)
0
 
ngerdaAuthor Commented:
The answer I was given just moved the error.  But I'm not heartless .... POINTS INCREASED!  

I took out $db Close and still get the error:

dbih_clearcom (h 0xb5d964, com 0x826560): FLAGS 0x111: COMSET Warn PrintError TYPE 3 PARENT DBI::db=HASH(0x7381b8) KIDS 0 (0 active) IMP_DATA undef in 'DBD::Oracle::st' NUM_OF_FIELDS 41 NUM_OF_PARAMS 0

As I am doing the following closure processing:

print "REPORT COMPLETE<BR>";
print "</CENTER>\n";
print "</BODY>\n";
print "</HTML>\n";
$db->disconnect() or die "Unable to disconnect : $DBI::errstr";  
}

sub getFormData
{
    my($hashRef) = shift;
    my($buffer) = "";   ..... SUBROUTINGES.

Thanks Please Help
(POINTS INCREASED)
Anna
0
 
b2piCommented:
('just moved the error' indicates that the problem was solved.  Unfortunately, you've got another one)

You're still not saying where you get that error message.

Before you answer, though, put the line

$| = 1;

at the top of your script. Put print statements around places where you think might be causing problems.  Then look at the output.
0
 
ngerdaAuthor Commented:
Now I get the error:

disconnect(DBI::db=HASH(0xb5a3f4)) invalidates 1 active statement. Either destroy statement handles or call finish on them before disconnecting. at W:\Inetpub\CERPS\cgi-bin\choose02.pl line 96. DBI Handle cleared whilst still active!.
dbih_clearcom (h 0xb5d550, com 0x8274f0): FLAGS 0x111: COMSET Warn PrintError TYPE 3 PARENT DBI::db=HASH(0xb5a3f4) KIDS 0 (0 active) IMP_DATA undef in 'DBD::Oracle::st' NUM_OF_FIELDS 41 NUM_OF_PARAMS 0

$db->disconnect() or die "Unable to disconnect : $DBI::errstr";   IS ON LINE 96.


0
 
b2piCommented:
Are you getting all the data you're expecting to get?
0
 
ngerdaAuthor Commented:
All data comming in fine .. it is just not a message I don't want the client to see.  
POINTS Raised.  Thank You for hanging in here with me.  DO I need to remove cursors or something before I disconnect?

0
 
ngerdaAuthor Commented:
You people are good.  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.