req: OO SQL gen module?

bjorn bjorn at roguewave.com
Mon Mar 6 16:29:09 EST 2000


Kragen Sitaker wrote:

> In article <38C2E097.BA3C38E8 at roguewave.com>,
> Bjorn Pettersen  <bjorn at roguewave.com> wrote:
> >A while ago I was attempting to swig a c++ library that did exactly this, but
> >ran into problems when I couldn't overload the individual comparison operators
> >for a python class, e.g. consider (assuming Table.__getitem__() returns a Column
> >object):
> >
> >    t = Table('foo')
> >    s = Select( t['col1'], t['col2'] )
> >    s.where( t['col3'] > 5 )  # oops, not possible
>
> That would be nice syntactic sugar, but you could just as easily say
> s.where(greater(t['col3'], 5)), couldn't you?

No, that can't be done since Python doesn't let you overload greater on differently
typed arguments like e.g. C++.  I started doing:

    s.where( t['col3'].greater(5) )

but that became exceedingly messy with anything but trivial expressions. Note that
greater(t['c3'], 5) would also quickly become messy if it was allowed, and since the
reason for doing all this in the first place was greater convenience (in addition to
masking quirks in individual databases' sql syntax) I gave it up and decided to wait
until the proper operator overloads were implemented in the Python core.

-- bjorn






More information about the Python-list mailing list