On May 3, 2011, at 3:22 AM, bool wrote: > >>> of course...just return the default execution as illustrated at >>> http://www.sqlalchemy.org/docs/core/interfaces.html#sqlalchemy.interf... . > > Mike, > > I want to return from the below method *without* actually > executing the insert. I think if I just return the default execution > as below, then it would execute insert right ( I tested it)? Let me > know if I am missing something...
OK well, if you were to return nothing, that "execute" call is actually the callable that runs the statement, so if you didn't call it, nothing would happen (in 0.6). But you'd usually get an error as you need to consider that when something is calling .execute(), it expects a result, and usually one that makes sense (has the expected state, like last inserted pk, etc.). So the use case of digging in to disable ad-hoc executions, since it was never feasible in any case, was removed in 0.7. You can change the details of the statement and parameters but within the official API returning None just raises an error. Since it's just Python its possible to put a proxy around the whole engine or connection object and intercept calls that way ( which is what 0.6's ConnectionProxy does), but the real problem is that you'd need to generate result object that makes sense to the caller, which would be a somewhat tedious task (very possible..but hacky). The real answer here is that you shouldn't *need* to do what you're trying to do - if you don't want a statement to be executed at all, the execute() call should not be emitted in the first place. The engine/connection is too low in the abstraction chain for controlling which statements get executed and which don't. > > > > =========================================================== > class MyProxy(ConnectionProxy): > def execute(self, conn, execute, clauseelement, *multiparams, > **params): > return execute(clauseelement, *multiparams, **params) > =========================================================== > > -- > 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. > -- 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.
