[Dbix-class] Problems using a database function in the where
clause
Matt S Trout
dbix-class at trout.me.uk
Fri Jul 25 01:39:25 BST 2008
On Wed, Jul 23, 2008 at 09:24:17AM +0200, Moritz Onken wrote:
>
> >>>>
> >>>>
> >>>>$rs->search({
> >>>>-and =>
> >>>>[
> >>>> {\"extract(year from age(NOW(),birthday))" => 22},
> >>>> {sex => "male"}
> >>>>]
> >>>>});
> >
> >Have you tried the other way around?
> >
> >-and => [
> > { '' => \'extract(year from age(NOW(),birthday))'},
> > {sex => "male"}
> >]
> >
> >I couldn't understand what is the 22 doing there.
>
> This query fetches all males who are 22 years old (postgresql syntax).
>
> >
> >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.
>
> The problem is that I create this query dynamically. It is much easier
> to push all
> the restrictions in an array and pass that array to search() than
> creating the raw
> sql from that array.
>
> But If there is no way to solve this with dbic I'll just write plain
> sql.
There is a way!
We already showed you!
Use a literal SQL chunk using a scalarref!
If you can't work it out, PASTE A CUT DOWN FORM OF THE CODE THAT MAKES
THE ARRAY, stop keeping saying "if there is no way to solve this" when
we've already told you how.
--
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