Hi,

Neither of these work, probably due to the fact that I didn't explain
it properly... What I'm trying to do it update a column in a table
with the value in another column, but for 20 columns, so:

col20 = col19
col19 = col18
col18 = col17
...

in sql this works:

update tab set col20 = col19 where var = whatever;

I could do each individually but I assuming this can be done in one
go, but it seems as though update doesn't like dynamic generated
keywords (column names).

Thanks


On 11 Jul, 18:27, Xavier Combelle <[EMAIL PROTECTED]> wrote:
> > Is possible to create dynamic sql in a web.update query, e.g.
>
> >  for i in range(10):
> >       atn = "at"+str(i)
> >       atn1 = "at"+str(i+1)
> >       web.update('atab', $atn='$atn1', vars=locals())
>
> > so the column name is dynamically updated on each iteration, e.g.
>
> > at0 = at1
> > at1 = at2
> > ...
>
> import web
> web.connect('sqlite',db=':memory:')
> web.query('create table foo (name,age)')
> web.insert('foo',name='Joseph',age=10)
> joe = 'Joseph'
> args = {'name':'bob', 'age':5}
> web.update('foo', where='name = $joe',   vars=locals(),**args)
> #web.update('foo', where='name = $joe',   vars=locals(),**{'name':'bob',
> 'age':5})
>
> for row in web.select('foo'):
>     print row
>
> seems do the job
>
> in your example I would do
>
> web.update('atab', vars=locals(), **{atn:atn1})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to