Steve Zatz wrote: > I occasionally need to drop into straight SQL when using a session > object with a threadlocal strategy. It is probably obvious but I am > not sure how to obtain the same connection that the session object is > using to execute straight SQL. >
You might try this: conn = session.connection(None) I'm not sure if that will work in your case, but it seems like the simplest solution. If that doesn't work try this: conn = session.connection(mapper) with a mapper that is bound to the engine on which you'd like to execute SQL. I worked with Mike to make the Session object more useful, but haven't had time to work on the Connection and Engine interfaces. There seems to be a lot of methods on those interfaces that are used internally by SA, but understanding them for external use is baffling to me. I haven't bothered to do it yet because I haven't needed too... IMO Session should have a connection() method that takes no arguments. Like this: conn = session.connection() The multiple-engines-per-session code makes the Session object seem unnecessarily complex to me, and it doesn't seem like most people will be using it that way either. I know there is at least one person using SA that needs this functionality, but I would have liked to see the Session work with a single connection by default and have the multiple-engine stuff implemented as a connection proxy (or something like that) that handles all the multi-engine complexity internally. Just my $0.02. Like I said, I haven't had time to look at this for a while. ~ Daniel _______________________________________________ Sqlalchemy-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

