• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

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
0
ngerda
Asked:
ngerda
  • 7
  • 6
1 Solution
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
b2piCommented:
No, you need to call finish on the handles....  i.e.

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

0
 
ngerdaAuthor Commented:
You people are good.  Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now