I'm building a complex ETL tool with SQLAlchemy that will sometimes
need to let the user "preview" a changed record - not actually carry
out the update, just find out which fields would be changed, and to
what values.  I'm having trouble figuring out a good way to do it.

Is there a way to get a sort of preview of an update - get information
about what updates are pending for the next flush, or get a flush to
report back its changes without actually performing it?

One approach would be to set echo to True, let the user see the echo,
then roll back the transaction, but there are a couple reasons I don't
think that will work for me.  I don't want to make the user mentally
parse SQL statements; I'd like to get a dict of the pending changes
and write my own code to display them attractively, instead.  Anyway,
I'm having trouble getting echo to work on this app.  (The whole thing
is part of a TurboGears project, and my echoes aren't showing up,
probably because of something I don't understand about the SQLAlchemy
logging configuration.)

Just getting to the bind variables that will ultimately be sent along
with the UPDATE statement would be a great solution, and I'm trying to
figure out where I could get them.  Right now, it looks like the
`params` dict is assembled in Mapper._save_obj in orm/mapper.py, used
at line 1376 to issue connection.execute, then discarded.  I'm
considering overriding Mapper with my own version whose __save_obj can
exit at this point, returning `params`, if it is invoked with a
"preview=True" parameter... but that seems a little scary.  __save_obj
is a long method, and I'd have to keep my app's version of it
carefully synched with the canonical sqlalchemy version indefinitely.

Thanks in advance for reading through, and for any any suggestions!
-- 
- Catherine
http://catherinedevlin.blogspot.com/
*** PyOhio * July 25-26, 2009 * pyohio.org ***

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to