[Dbix-class] Getting a' count' value

Emmanuel Quevillon tuco at pasteur.fr
Thu May 14 12:48:19 GMT 2009


Emmanuel Quevillon wrote:
> Hi,
> 
> Sorry if my question looks stupid, but I'd like to retrieve the
> value of a count returned by an SQL query.
> 
> I tried different things but it always return 1
> 
> Here is the way I'd like it to work:
> 
> ...
> acc => $g->name(),
> num => $c->model('Table')->search({'id' => $g->id},<CODE>
> 
> where I tried to replace <CODE> with :
> 
> 1- )->all()
> 2- { select =>[{'count' => '*'}],as => ['cnt']
> })->next->get_column('cnt')
> 
> But each time, $hash->{num} =  1!
> 
> The SQL request are well generated in each case :
> 
> SELECT COUNT( * ) FROM Table me WHERE ( id = '1012' ):
> SELECT COUNT( * ) FROM Table me WHERE ( id = '296' ):
> 
> 
> 
> What am I doing wrong?
> Any advice welcome
> 
> Regards
> 


OK I found!! :(

Sorry, it was my mistake in one of my Template.... I didn't use the
right value...
So ->count() works perfectly!
Shame on me :)

Thanks for replies
Regards

-- 
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------



More information about the DBIx-Class mailing list