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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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!

In reply to while($sth->fetch()) help by Zo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2019-07-17 23:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?