Solved

print after while loop not executing.

Posted on 1998-11-19
13
326 Views
Last Modified: 2010-03-04
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
Comment
Question by:ngerda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 

Author Comment

by:ngerda
ID: 1206371
Adjusted points to 155
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1206372
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
 

Author Comment

by:ngerda
ID: 1206373
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
Independent Software Vendors: 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!

 
LVL 5

Expert Comment

by:b2pi
ID: 1206374
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
 

Author Comment

by:ngerda
ID: 1206375
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
 
LVL 5

Expert Comment

by:b2pi
ID: 1206376
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
 

Author Comment

by:ngerda
ID: 1206377
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
 
LVL 5

Expert Comment

by:b2pi
ID: 1206378
('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
 

Author Comment

by:ngerda
ID: 1206379
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
 
LVL 5

Expert Comment

by:b2pi
ID: 1206380
Are you getting all the data you're expecting to get?
0
 

Author Comment

by:ngerda
ID: 1206381
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
 
LVL 5

Accepted Solution

by:
b2pi earned 180 total points
ID: 1206382
No, you need to call finish on the handles....  i.e.

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

0
 

Author Comment

by:ngerda
ID: 1206383
You people are good.  Thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question