try:
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
if queries:
query=reduce(lambda x,y: x|y,queries)
records[tablename]=db(query).select()
return dict(records)
Do you have tables with no 'text' or 'string' fields? That could have
caused the problem.
On Oct 29, 11:04 am, __Kyo__ <[email protected]> wrote:
> 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 <[email protected]> wrote:
>
> > seems to specific to me, but we could have a plugin for it.
>
> > Massimo
>
> > On Oct 28, 9:55 pm, Alex Fanjul <[email protected]> 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.
> > > [email protected]
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---