CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
PERL, DBI and While loop - Fetch row at a time and re execute the query to fetch the next row

 



sha37
Novice

Feb 24, 2010, 2:06 PM

Post #1 of 2 (1418 views)
PERL, DBI and While loop - Fetch row at a time and re execute the query to fetch the next row Can't Post

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
$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;


}


FishMonger
Veteran / Moderator

Feb 25, 2010, 9:54 AM

Post #2 of 2 (1393 views)
Re: [sha37] PERL, DBI and While loop - Fetch row at a time and re execute the query to fetch the next row [In reply to] Can't Post

When posting code, you need to put that code within code tags.

If you don't use the code tags, then most people won't help you because the code is harder to read/follow.

One problem you have is with this line:

Code
if (@$)

The var is:

Code
$@


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives