PERL and DBI and WHILE LOOP

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

    PERL and DBI and WHILE LOOP

    Hi,

    I have to code this part in perl and using DBI.

    1. I have a SQL select query which fetches some rows based on order.
    2. I have to fetch each row at a time, once i fetch the first row i process the fields and some response is returned.
    3. now I have to fetch the next row again and do the step 2.

    This whole process should be in a while loop since this perl script will be running everytime based on some sleep command and fetched data and process.

    Please help, need this as soon as possible.

    Here is my sample code
    Code:
    $signal = 0;
    while (!$signal)
    {
    $sql = getsqlquery();
    $sth = $dbh->prepare($sql);
    eval
    {
    $sth->execute;
    };
    
    if (@$)
    {
    addToLogFile($followerName, 'ERROR', "Fetching rows from query execute command failed." . $dbh->errstr() . "Trying to connect again in 10 secs");
    sleep(30);
    $signal = 0; 
    }
    
    if ($sth->rows == -1)
    {
    addToLogFile($followerName, 'INFO', "No Commands in the query table. Sleeping for 10 seconds to recheck the table.");
    sleep 10;
    $signal = 0;
    }
    while (my @data = $sth->fetchrow_array())
    {
    $signal = &processCommand(@data);
    }
    }
    sub processCommand()
    {
    do some sql queryies ;
    
    return 0;
    
    
    }
    Last edited by numberwhun; Feb 25 '10, 01:50 AM. Reason: Please use CODE tags!!!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    First, please use code tags around code you place in the forums.

    Second, I read your post, but do you have a question?

    Regards,

    Jeff

    Comment

    • sha37
      New Member
      • Feb 2010
      • 4

      #3
      the above code does not work. if i have 40 records in the database, for each record it runs 40 times and its runs 40x40 times.

      Comment

      Working...