On Friday, October 3, 2003, at 02:44 PM, Ian Bicking wrote:
> On Friday, October 3, 2003, at 01:40 PM, Brad Bollenbach wrote:
>>> Ideally I'd like to be able to perform this type of query using
>>> Python's "in" operator. From reading through SQLBuilder.py this
>>> seems to be already overloaded to support SQL "something IN
>>> ('blah1', 'blah2')" operations. Is there any way this could be
>>> inteligently overloaded to perform like %% queries on strings and IN
>>> queries on tuples?
>>
>> Python's "in" operator checks for the existence of a value in a
>> sequence. What you're trying to do is ask for all the objects (or all
>> the SQLObjects, as it were :) that meet a certain criteria. The
>> semantics are different.
>
> Not exactly -- SQLBuilder (which you get at with SomeSQLObject.q)
> captures Python expressions (to the degree possible), which can then
> be turned into SQL clauses. In this particular case ("in") I don't
> think Python makes it possible to do this, but several operators can
> be overloaded like this.
Perhaps the semantics aren't really completely different, but as you
say, 1. Python would actually have to allow this (it may or may not, I
haven't checked), 2. it would have to be written like:
Foo.select('bar' in Foo.q.baz)
instead of the normal:
Foo.select(Foo.q.baz == 'baz')
used for direct comparisons. This would be too inconsistent (and
perhaps too easy to confuse with writing the other way around), IMHO.
--
Brad Bollenbach
BBnet.ca
|