Hi, i have a problem running this.

def index():
    records = {}
    if request.vars.boton:
        key=request.vars.dato
        for tablename in db.tables:
            table=db[tablename]
            fields=[table[fieldname] for fieldname in table.fields]
            queries=[field.like('%'+key+'%') for field in fields if
field.type in ['text','string']]
            print queries
            query=reduce(lambda x,y: x|y,queries)
            records[tablename]=db(query).select()
    return dict(records)

The error message:
query=reduce(lambda x,y: x|y,queries)
TypeError: reduce() of empty sequence with no initial value

I would apprecaite a lot if you could help me with this.



On Oct 28, 11:51 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> seems to specific to me, but we could have a plugin for it.
>
> Massimo
>
> On Oct 28, 9:55 pm, Alex Fanjul <alex.fan...@gmail.com> wrote:
>
>
>
> > Massimo, what about a full text database search engine, but at web2py
> > level to abstract databases peculiarities?
> > Maybe its a silly idea...
> > Alex F
>
> > El 29/10/2009 2:21, mdipierro escribió:
>
> > > I think it does not show because you overwrite the variable at every
> > > iteration
> > > I would try something like this
>
> > > def index():
> > >      key=request.vars.baton
> > >      records = {}
> > >      for tablename in db.tables:
> > >          table=db[tablename]
> > >          fields=[table[fieldname] for fieldname in table.fields]
> > >          queries=[field.like('%'+key+'%') for field in fields if
> > > field.type in ['text','string']]
> > >          query=reduce(lambda x,y: x|y,queries)
> > >          records[tablename]=db(query).select()
> > >      return dict(records)
>
> > > It should display a list of records that match by any field without
> > > duplicates
>
> > --
> > Alejandro Fanjul Fdez.
> > alex.fan...@gmail.comwww.mhproject.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to