This db(query).update(db.X.x2= db.X.x2+10) should be
db(query).update(x2= db.X.x2+10) On Monday, 25 November 2013 16:56:03 UTC-6, Yohai Bar Sinai wrote: > > Hello all, > > I have a pretty peculiar problem, and I hope there's an elegant solution > somewhere. > > Lets say I have a table named X with 5 integer fields x0, x1, x2. I want > to update the fields in some rows, doing something like > > db(query).update(db.X.x0= 10) > db(query).update(db.X.x1= 10) > db(query).update(db.X.x2= 10) > > This is pretty easy. However, in reality I have around 200 fields, which > makes it impractical to write a line for each field. So I tried to iterate > over the fields. I can't seem to find an elegant way to do it, and the only > way that seems to work is quite convoluted: > > for i in range(3): > db(query).update(**{db.X['x'+str(i)].name:10}) > > This, quite surprisingly, works. However, with this approach I cannot use > an expression in the value of the update. That is, I can't write the > equivalent to > > db(query).update(db.X.x2= db.X.x2+10) > > which would be > > for i in range(3): > db(query).update(**{db.X['x'+str(i)].name: db.X['x'+str(i)].name+10}) > > any help will be much appreciated. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.