[Dbix-class] Problems using a database function in the where clause

Matt S Trout dbix-class at trout.me.uk
Wed Jul 23 04:01:39 BST 2008


On Tue, Jul 22, 2008 at 09:14:15AM +0200, Moritz Onken wrote:
> 
> Am 21.07.2008 um 15:01 schrieb Eden Cardim:
> 
> >On Mon, Jul 21, 2008 at 4:59 AM, Moritz Onken  
> ><onken at houseofdesign.de> wrote:
> >>But how can I rewrite my query to the other format without writing  
> >>the raw
> >>sql where clause?
> >>Why is it not possible to write my query with as scalar ref:
> >>
> >>$rs->search({
> >>-and =>
> >>  [
> >>   {\"extract(year from age(NOW(),birthday))" => 22},
> >>   {sex => "male"}
> >>  ]
> >>});
> >
> >Because the '=>' operator stringifies it's left operand, thus you'll
> >end up with some perl internal debug value instead of the string you
> >intended. What's the problem with writing raw SQL?
> 
> The idea of DBIC is not to write raw sql, right?

But when you're using db-specifc stuff nobody';s written general support
for, a small chunk of raw SQL that solves the problem, encapsulated in
a method on your resultset, is just fine.

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list