The "table.c" object supports dictionary-style access, so you should be
able to use something like this:
colname = 'Program'
column = table.c[colname]
update = table.update(column=='project-name', values =
{test:'program'})
However, in general, if you want to get a named attribute of an object,
and the name is stored in a variable, you can use Python's "getattr"
function. This code should also work:
colname = 'Program'
column = getattr(table.c, colname)
update = table.update(column=='project-name', values =
{test:'program'})
Hope that helps,
Simon
Thank you for the response. However, that is not the problem. If I do
update = table.update(project.c.ProjectID=='project-name', values =
{project.c.ProjectID:'program'})
print update
update.execute()
everything works fine.
if I do this:
test = 'table.c.'+columns[0] #columns is a list which contains the
columns names
update = table.update(test == 'project-name', values={test:'program'})
update.execute()
it does not work. I get an error that there is no such column.
I need to be able to update columns dynamically where I do not have a
prior knowledge of what tables and what are the table columns that may
exist. How can I do that if at all?
Thank you very much. I'll try it. Is there a better way of doing this-- I mean there must be since this is necessary for any application needing to modify a database where generally tables are accessed dynamically.