[Dbix-class] Chained resultsets and WHERE operators

Alexander Hartmaier alexander.hartmaier at t-systems.at
Thu Nov 11 07:37:54 GMT 2010


Note that by swapping column and value you will lose the advantage of
bind which makes sql injection impossible.

--
Best regards, Alex


On Wed, 2010-11-10 at 06:34 +0100, Mike Raynham wrote:
> On 09/11/10 22:26, Peter Rabbitson wrote:
> >
> > -nest...? what...?
> >
> > I still don't understand how this is different from anything you've showed
> > us in the thread so far. You said you want to do:
> >
> > WHERE
> > ($start_date >= start_date AND $start_date <= end_date)
> > OR
> > ($end_date >= start_date AND $end_date <= end_date)
> >
> > In SQLA it is assumed that the lhs is a column and the rhs is a bind value
> > (this is a *generalization*, there are all kinds of exceptions, but as a
> > generalization it will suffice)
> >
> > So we rewrite this as:
> > (start_date <= $start_date AND end_date >= $start_date)
> > OR
> > (start_date <= $end_date AND end_date >= $end_date)
> >
> > So then it boils down to:
> > [
> > { start_date => { '<=', $start_date }, end_date => { '>=', $start_date } },
> > { start_date => { '<=', $end_date }, end_date => { '>=', $end_date } },
> > ]
> >
> > That's it. No -nest, no braindamage.
> >
> > Cheers
>
> Hi Peter,
>
> Thank you for you input, and your solution.  I appear to have created
> some confusion, so please let me attempt to clarify things.
>
> My original question was about chaining with an OR instead of an AND.
> You pointed out that:
>
>  > Chaining implies AND ing (tightening the condition more
>  > and more)
>
> Ronald J Kimball provided an elegant solution which you kindly
> simplified.  I thanked you both for this, and said that I liked the
> solution and that I would use it.
>
> I then mentioned that if I were to write the query manually, I would
> probably swap the column and bind values around.  This is simply because
> that way the meaning looks a little clearer to me.  I fully understand
> that in this case, it doesn't affect the query in any way.  I also
> pointed out that it would do exactly the same thing as the original query.
>
> I didn't think that it was possible (at least not easily or sensibly) to
> swap the column and bind values around when generating a search with
> DBIx::Class::Resultset, and was perfectly happy to leave it at that.
> However, your response to this was:
>
>  > I don't see why not... ? Explain what do you perceive the holdup would
>  > be.
>
>  From that, I assumed that maybe there is a way to easily swap the
> column and bind values around.  I checked the DBIx::Class::Manual::FAQ,
> and found a mention of -nest, which appeared to offer a way of doing it.
>   I didn't try it.  I was, and still am, happy to restructure my
> original query to incorporate your solution.
>
>
>
>
> Regards,
>
> Mike
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list