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
Expand|Select|Wrap|Line Numbers
- $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;
- }