Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

while($sth->fetch()) help

by Zo (Scribe)
on Mar 05, 2003 at 20:15 UTC ( #240687=perlquestion: print w/replies, xml ) Need Help??

Zo has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,
I don't know why my code isn't working. The script I have has been running for months, almost a year without a problem on an NT server, now I'm just cleaning it up to run on an AIX machine. I do a DBI connection and get data from an Oracle database. Now I want to use the data that is extracted from the db table. Remember this has worked on NT for a while with no errors.

The following code has been edited for printing here online, but the part that doesn't work is it is not getting into the 'while' loop where '->fetch' is.
Thank you in advance for the help. -Zo
#!/usr/bin/perl print " 1 starting \n"; use strict; use DBI; # output file my $newfile = "crs_batch_output.txt"; open(BATCH, ">>$newfile") || die "Can't open $newfile : the crs_batch_ +output.txt file. $!"; print "2 ....... set datestamp: ".$datestamp."\n"; print "2 a ...... was able to open temp flag \n"; print "3......... was once flock'd \n"; ##### # initialize the variables my $linecount = 0; my $table = 'cscadmin.crs_batch_lines'; my @fields = qw(batch_line rowid); my %results; my $fields = join(', ', @fields); print " 4 ..... before the db connect.. \n"; # connection to database my $dbh; eval { $dbh = DBI->connect("dbi:Oracle:db", "user", "password",{RaiseErro +r=>1,AutoCommit=>1}); }; if ( $@ ) { print BATCH $@." ".$datestamp."\n"; print " 5 ..... in the first if to eval the error messag and to print +the datestamp to the file \n"; open(TEM4,">$tempfile") || die "Unable to open tempflag file for u +nblocking. $!"; print " 6 \n"; close(TEM4); } # if ($@) print "7 .. if no 5 then that's a good and no 6 then either thing \ +n"; my $sth = $dbh->prepare("Select $fields From $table Where exe_c = 'N' +AND rownum < 151 "); $sth->execute(); print " 7 a ---- ".$fields." -- fields, and table:".$table." \n"; @results{@fields} = (); $sth->bind_columns(map{\$results{$_} } @fields); print "8 ......... after the execute, before the while fetch print \n +"; while($sth->fetch()) { print " 8 a ... in while fetch loop\n"; # prints to screen to view process running print "$results{batch_line} <$results{rowid}>\n"; # counts the batch line being read $linecount++; print "9 ... should be seeing batch lines before this statement.... +linecount ".$linecount." \n"; $results{batch_line}=~s/ D\:\\Report_Schedules\\RunRpt\\.exe/ runrepor +t\.sh/g; # executes the batch line # system($results{batch_line}); print BATCH $results{batch_line}." ".$datestamp; print $results{batch_line}." ".$datestamp."\n"; my $bsql = "UPDATE cscadmin.crs_batch_lines SET exe_c = 'Y' WHERE exe +_c = 'N' AND rowid = ('$results{rowid}')"; my $sth2= $dbh->prepare($bsql); $sth2->execute(); } # while # close oracle connection $sth->finish(); $dbh->disconnect(); # print count of batch lines print BATCH "\nLines extracted this period: ".$linecount."\n"; print "10 ... after disconnect \n"; # close new .txt file close (BATCH); print "11 ........ finished at the end \n";

Any ideas? I've looked through a few books and online and now I come here for help. Thanks again!

Replies are listed 'Best First'.
Re: while($sth->fetch()) help
by dws (Chancellor) on Mar 05, 2003 at 20:40 UTC
    the part that doesn't work is it is not getting into the 'while' loop

    Have you verified that there's really data in cscadmin.crs_batch_lines that satisfies the query you're using? Quite a few, "It used to work, and I didn't change anything!" problems can be traced back to unnoticed changes in data.

      Actually after I posted it, that's what I thought too... I'm trying to run data integrity testing and DBI connection now with a separate script. Thanks for the input!
        .... ugh... ok.. the next vote/poll on this site should be
        "Who's the biggest moron on this site?"..
        I would vote for myself. It wasn't my code, it was my "select" statement itself... where it was looking for a 'N'.. and in the table I just checked, all are set to 'Y'.

        This is why I ask here, you are all my "cyber-eyes" to help when I get "coder's block".


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://240687]
Approved by bart
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2020-08-09 22:44 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (55 votes). Check out past polls.