On Dec 2, 2009, at 5:32 PM, jsa wrote:

> In my SQLAlchemy app, I want to generate a dedicated, low-level log
> output that will capture sql queries and parameters in a custom-
> defined format, as well as separate elapsed times for execute and
> fetch, and number of rows fetched.  In addition I'd like identifiers
> for the session / connection to appear in the log, so it is possible
> to process the log file and identify all the query activity associated
> with a given user activity or even physical db session/connection.
> 
> Can anyone the best starting point to make this kind of extension?
> I'm fairly new to the library.  I'm hoping to find a way that doesn't
> break encapsulation, or adding custom behavior in a lot of places.


for most of what you want, you want to use ConnectionProxy:  
http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/interfaces.html#sqlalchemy.interfaces.ConnectionProxy

as far as number of rows fetched, that number may or may not be available 
depending on the DBAPI in use.   there may not be any "number" available until 
the ResultProxy is fully consumed.    if cursor.rowcount doesn't have it 
(rowcount is normally reserved for rows matched during an UPDATE or DELETE, 
though some DBAPIs put the number of rows SELECTed in it), you might have to 
wrap the cursor in some kind of proxy that will count rows as they are fetched, 
which is a slightly ambitious and performance-hindering project, but you'd also 
do that within ConnectionProxy.

see the example at http://techspot.zzzeek.org/?p=31 too.



> 
> Thanks!
> Jim
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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 sqlalch...@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