[sqlalchemy] simple update without a session or mapping

2011-01-26 Thread Josh Stratton
I'm currently interfacing with an Oracle db using sqlalchemy without
any sessions or mappings.  Selects and inserts work great, but I'd
like to be able to update a row without having to delete and reinsert
it.

# remove the id
table.delete(table.c.id == row['id']).execute()

# add it back with new value
row['name'] = 'now frank'
self.conn.execute(table.insert(), row)

I realize there there's an update function in table, but I'm at a loss
as to how to use the syntax for it.  I'm just changing one or two
non-primary-key values.  All the examples I see use the ORM mappings
with sessions, or use the update to change every field in a column.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] simple update without a session or mapping

2011-01-26 Thread Michael Bayer
the docs for update() are at:

tutorial: http://www.sqlalchemy.org/docs/core/tutorial.html#inserts-and-updates
API: 
http://www.sqlalchemy.org/docs/core/expression_api.html#sqlalchemy.sql.expression.update


On Jan 26, 2011, at 2:14 PM, Josh Stratton wrote:

 I'm currently interfacing with an Oracle db using sqlalchemy without
 any sessions or mappings.  Selects and inserts work great, but I'd
 like to be able to update a row without having to delete and reinsert
 it.
 
# remove the id
table.delete(table.c.id == row['id']).execute()
 
# add it back with new value
row['name'] = 'now frank'
self.conn.execute(table.insert(), row)
 
 I realize there there's an update function in table, but I'm at a loss
 as to how to use the syntax for it.  I'm just changing one or two
 non-primary-key values.  All the examples I see use the ORM mappings
 with sessions, or use the update to change every field in a column.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.