OR and LIKE on GAE

12 views
Skip to first unread message

mdipierro

unread,
Oct 26, 2009, 11:34:24 AM10/26/09
to web2py-users
As you know assuming:

db.define_table('a',Field('b','integer'))

the following expressions do not work on gae:

rows1 = db((db.a.b<10)|(db.a.b>5)).select()
rows2 = db(db.a.b.belongs(2,3,4)).select()

So with the latest code in trunk you can now do:

rows1 = db(db.a.b<10).select() | db(db.a.b>5).select()
rows2 = db(db.a.b==2).select() & db(db.a.b==3).select() & db
(db.a.b==4).select()

(the | will prevent duplicate records, the & will not and therefore is
faster)
of course this also works with relational databases although it is
less efficient than the original expressions.

I am also considering something like (not yet in trunk)

rows2 = (db(db.a.b==2).select() & db(db.a.b==3).select()).filter
(query=..., orderby=...)

To allow web2py level searching and re-sorting results from the
database. It should be easy to implement as a method of class Rows in
sql.py.

Comments? Any help with this will be appreciated.

Massimo



Thadeus Burgess

unread,
Oct 26, 2009, 11:54:01 AM10/26/09
to web...@googlegroups.com
If you perform


rows1 = db(db.a.b<10).select() | db(db.a.b>5).select()

This is all on the python level? Strictly to allow for joins on gae?

-Thadeus

mdipierro

unread,
Oct 26, 2009, 12:56:27 PM10/26/09
to web2py-users
On Oct 26, 10:54 am, Thadeus Burgess <thade...@thadeusb.com> wrote:
> If you perform
>
> rows1 = db(db.a.b<10).select() | db(db.a.b>5).select()
>
> This is all on the python level?

Yes

> Strictly to allow for joins on gae?

It is not a join. It just merges two sets of records. The main purpose
is to bypass the GAE limitation but it can have uses on relational
databases too.

>
> -Thadeus

mattynoce

unread,
Oct 26, 2009, 2:12:26 PM10/26/09
to web2py-users
i think this is a great idea. i'm currently trying to implement a
search that would ordinarily use LIKE and have had two problems:
1) i can't use LIKE, so your new suggestion would be wonderful. i was
planning to write it on my own, so having syntax for it would be
wonderful.
2) i would like my search to be able to look through different fields,
like a single search box that looks in first name and last name. being
able to pull those two (or more) queries and then sort them as a
single result set would be great.

matt
Reply all
Reply to author
Forward
0 new messages