how to fetch one row at a time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sha37
    New Member
    • Feb 2010
    • 4

    how to fetch one row at a time

    Hi,

    I have a below subroutine called getqueryresults ()


    The below function just takes the data from ABC table and returns one row. This function exists in db.pl file
    Code:
    sub getqueryresults() { 
        my $followerName = $_[0];
         my $sql = "SELECT * ABC WHERE (delay is null or delay < sysdate) AND id = ? ORDER BY qcounter, priority";      
     my $sth = $dbh->prepare($sql);   
      $sth->bind_param(1, $followerName);   
      eval     {         $sth->execute;     };      
        if ($@)     {         $log->error("dbh->errstr());     }    
       if ($sth->rows == -1)     {         $log->error("No  rows.");     }    
     my @data= $sth->fetchrow_array();     return @data; }
    
    
    
    
    this below file XX.pl file calls getqueryresults(); 
    
    
      #!/usr/bin/perl   
    require 'db.pl';
       $signal = 1;  
     while ($signal)   {
       $signal = &processCommand();   } 
      sub processCommand() {  
      my ($Id, $sId, $rd, $cmd) = getqueryresults("XX");     
      print $Id . "sd==>" . $sId . "rd===>"  . $rd ."\n";    
     return $signal = 1;
     }


    This above print always prints the same row everytime. is there something i am doing wrong. I want to print a next row everytime.

    It will be great if someone can take a loot at it.
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    See my answer on your cross post.

    Comment

    Working...