On Tue, Mar 20, 2018 at 4:15 PM, Uri Okrent <[email protected]> wrote:
>
> On Thursday, March 15, 2018 at 9:11:06 AM UTC-4, Mike Bayer wrote:
>>
>> use execution events for this, before_cursor_execute tends to be a
>> good choice (but not the only one):
>>
>>
>> http://docs.sqlalchemy.org/en/latest/core/events.html?highlight=before_cursor_execute#sqlalchemy.events.ConnectionEvents.before_cursor_execute
>
>
> thanks this looks like what I was looking for.
>
>>
>> within the event, take a look at the context to see what kind of query
>> it is (or just inspect the string SQL itself).  context has
>> "context.compiled.statement", "context.isinsert", "context.isupdate",
>> "context.is_crud", "context.isddl" (clearly I'll have to make the
>> names more consistent someday) etc.
>
>
> The ExecutionContext docs linked from there
> (http://docs.sqlalchemy.org/en/latest/core/internals.html#sqlalchemy.engine.interfaces.ExecutionContext)
> lists 'isinsert', and 'isupdate', however I don't see 'is_crud' or 'isddl'.
> Are these last two internals or are they public and just haven't been
> documented? I assume that is_crud includes both isinsert and isupdate?  Is
> this determination being made at the sqlalchemy core abstraction layer
> level, or on the generated statement itself?  For example, will isinsert be
> true for something like this: `session.execute(text("""INSERT..."""))`?


this is semi-documented / semi-private stuff.  you can derive it
yourself if you just look at the type of context.compiled.statement
that's passed.   If a text() is passed, then you'd need to run a
regular expression on the text within it.     I recommend making a
test script to play with, put a pdb.set_trace() inside that event, and
just poke around at what you get for different scenarios.


>
> thanks again
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to