On Jan 15, 9:20 am, "Rick Morrison" <[EMAIL PROTECTED]> wrote:
> Hey Mike
>
> You don't need to go through that. Just populate the dictionary used for the
> execute() with the appropriate column name as the key, and you're good to
> go.
>
> On Jan 15, 2008 10:05 AM, Mike <[EMAIL PROTECTED]> wrote:
>
>
>
<content snipped for brevity>
>
> > if colName == 'someColName':
> > tbl.update(tbl.c.dateworked == mydate).execute(dict(columnname
> > =newvalue))
> > elif colName == 'anotherColName':
> > tbl.update(tbl.c.dateworked ==
> > mydate).execute(dict(othercolumnname =newvalue))
> > else:
> > pass
>
> > This will work, but it's not quite as elegant as I had hoped. The
> > sessions method looks like it would have the same issue. Thanks for
> > the advise.
>
> > Mike
Ok...so here goes:
# Column names:
# netname
# pref_name
# pref_value
def main(tblName, key):
engine = create_engine('mssql://dbName:[EMAIL PROTECTED]/%s' % tblName)
conn = engine.connect()
# create MetaData
meta = MetaData()
# bind to an engine
meta.bind = engine
# create metadata
meta.create_all()
tbl.update(tbl.c.netname=='saw').execute(dict(key = 'New Val'))
if __name__ == '__main__':
tblName = 'tbl_Acct_Prefs'
pref_value = 'someval'
main(tblName, pref_value)
This returns
Incorrect syntax near the keyword 'WHERE'.
DB-Lib error message 10007, severity 5:
General SQL Server error: Check messages from the SQL Server.
'UPDATE [tbl_Acct_Prefs] SET WHERE [tbl_Acct_Prefs].netname = %
(tbl_Acct_Prefs_netname_1)s' {'tbl_Acct_Prefs_netname_1': 'saw'}
If I just do this:
if __name__ == '__main__':
tblName = 'tbl_Acct_Prefs'
main(tblName, pref_value)
I get a variable undefined error, which I understand. I think I know
what you mean, but I don't know how to pass in an object that doesn't
exist yet. I tried creating a dict inside the main() where I did this:
colDict = {'netname':netname, 'pref_name':pref_name,
'pref_value':pref_value}
tbl.update(tbl.c.netname=='saw').execute(dict(colDict[key] = 'New
Val'))
where "key" was one of the string keys in colDict...but it didn't like
that much either.
ORM appears to be harder to grasp than I had originally thought.
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---