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!