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: DBI:
SELECT Finding if result returned is 0

 



sarthakganguly
Novice

Jul 25, 2009, 11:34 PM

Post #1 of 5 (4449 views)
SELECT Finding if result returned is 0 Can't Post

Hi,
I have the following script for fetching some data from mySql DB.

my $query_select_groups="SELECT GROUPS.group_id,GROUPS.article_id FROM GROUPS WHERE group_id = (SELECT DISTINCT GROUPS.group_id FROM GROUPS LIMIT 1) AND flag=0";

my $query_select_groups_handle = $connection->prepare($query_select_groups);

$query_select_groups_handle->execute() or die "Error in fetching data";

query_select_groups_handle->bind_columns(\$group_id,\$article_id);

while($query_select_groups_handle->fetch()){
print "group id $group_id \n ";
print "article id $article_id \n";
push(@articles,$article_id);
}

If the query returns 0 rows I want the program to sleep for 30 secs and try again.

q1)How to find if the query is returning 0 or not? Is this going to help ....?
if($query_select_groups_handle->{NUM_OF_FIELDS} eq 0){
goToSleep();
}

q2)If some error occurs I dont want the program to die..I want it to log and go to sleep. For dat instead of

$query_select_groups_handle->execute() or die "Error in fetching data";

what can I use?
Please suggest me some solutions...
Thanks in Advance

Thanking you
regards
Sarthak


FishMonger
Veteran / Moderator

Jul 26, 2009, 8:45 AM

Post #2 of 5 (4444 views)
Re: [sarthakganguly] SELECT Finding if result returned is 0 [In reply to] Can't Post

A1) http://search.cpan.org/~timb/DBI-1.609/DBI.pm#rows

A2) Write a subroutine that does what you want and call that sub instead of die.


sarthakganguly
Novice

Jul 26, 2009, 8:50 AM

Post #3 of 5 (4442 views)
Re: [FishMonger] SELECT Finding if result returned is 0 [In reply to] Can't Post

Hi,
Thanks a lot for ur reply.
A1)I have gone through the documentation on cpan but couldn't understand how to do it.
A2)Thanks a lot for it.

Thanking you
regards
Sarthak


FishMonger
Veteran / Moderator

Jul 26, 2009, 9:12 AM

Post #4 of 5 (4440 views)
Re: [sarthakganguly] SELECT Finding if result returned is 0 [In reply to] Can't Post


Code
while($query_select_groups_handle->fetch()){ 
print "group id $group_id \n ";
print "article id $article_id \n";
push(@articles,$article_id);
}

if( $query_select_groups_handle->rows < 1 ) {
goToSleep();
}



sarthakganguly
Novice

Jul 26, 2009, 9:20 AM

Post #5 of 5 (4438 views)
Re: [FishMonger] SELECT Finding if result returned is 0 [In reply to] Can't Post

Thanks a lot for the quick reply.

 
 


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

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