By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,525 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

PERL and DBI and WHILE LOOP

P: 4
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
Expand|Select|Wrap|Line Numbers
  1. $signal = 0;
  2. while (!$signal)
  3. {
  4. $sql = getsqlquery();
  5. $sth = $dbh->prepare($sql);
  6. eval
  7. {
  8. $sth->execute;
  9. };
  10.  
  11. if (@$)
  12. {
  13. addToLogFile($followerName, 'ERROR', "Fetching rows from query execute command failed." . $dbh->errstr() . "Trying to connect again in 10 secs");
  14. sleep(30);
  15. $signal = 0; 
  16. }
  17.  
  18. if ($sth->rows == -1)
  19. {
  20. addToLogFile($followerName, 'INFO', "No Commands in the query table. Sleeping for 10 seconds to recheck the table.");
  21. sleep 10;
  22. $signal = 0;
  23. }
  24. while (my @data = $sth->fetchrow_array())
  25. {
  26. $signal = &processCommand(@data);
  27. }
  28. }
  29. sub processCommand()
  30. {
  31. do some sql queryies ;
  32.  
  33. return 0;
  34.  
  35.  
  36. }
  37.  
Feb 24 '10 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Feb 25 '10 #2

P: 4
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.
Feb 25 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.