Solved

print after while loop not executing.

Posted on 1998-11-19
13
297 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now