On Jan 8, 2014, at 2:39 AM, limodou <limo...@gmail.com> wrote:

> 
> 
> 
> On Wed, Jan 8, 2014 at 3:31 PM, Wichert Akkerman <wich...@wiggy.net> wrote:
> 
> On 08 Jan 2014, at 01:26, limodou <limo...@gmail.com> wrote:
> 
> > But I don't know why make this decision. Because "where NULL" will get 
> > nothing. And in 0.8.X version, I need to combine multiple condition 
> > according user input to one condition, so my code just like:
> >
> > cond = None
> > for c in conditions:
> >     cond = c & cond
> 
> Why don’t you change the initial value to true() instead of None? If I read 
> the documentation correctly that should work correctly in both SQLAlchemy 
> versions.
> 
> 
> Even cond='' is correctly also, but I just think NULL is not a valid 
> condition expression in SQL, so I think the old appoach maybe better. 

“WHERE NULL” is not valid, that’s true; hence neither is select.where(None) 
anymore, which is what would happen above if “conditions” were empty (and if 
conditions is guaranteed not empty, you could say “cond = conditions[0]; for c 
in conditions[1:]:…” )

The change includes that it’s safe to use “true()” explicitly and it will be 
folded in (i.e. not rendered) when used with “AND”.   Some people were doing 
the above pattern that way anyway, now that way works on all backends.

in any case it’s better to use and_():

cond = and_(*conditions)

it’s less code and way fewer method calls internally. Also when you have “cond 
= c & cond”, you end up with a structure like "a & (b & (c & (d & e)))” which 
eventually will cause a recursion overflow when parsed, if there’s too many 
conditions.






> 
> -- 
> I like python!
> UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
> UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
> My Blog: http://my.oschina.net/limodou
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to