-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I would like to write a patch for ticket #877.

What is the best method to implement the requested feature?

The ExecutionContext class has a post_exec method, so the implementation
for the psycopg2 driver can override this method, check for the notice
messages and log them.

Attached is a very simple patch.

The problem is that NOTICE messages will only be logged if echo
parameter is set to True, in the create_engine function; however I
usually don't want to echo all SQL statatements, but I'm interested to
see NOTICE messages.


By the way, it seems there is a bug in the documentation:
http://www.sqlalchemy.org/docs/reference/sqlalchemy/connections.html?highlight=create_engine#sqlalchemy.create_engine

"""echo=False – if True, the Engine will log all statements as well as a
repr() of their parameter lists to the engines logger, which defaults to
sys.stdout. The echo attribute of Engine can be modified at any time to
turn logging on and off. If set to the string "debug", result rows will
be printed to the standard output as well. This flag ultimately controls
a Python logger; see dbengine_logging at the end of this chapter for
information on how to configure logging directly."""

However there is no dbengine_logging section!



Thanks  Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkuKmCEACgkQscQJ24LbaURdJgCeIPIbeYfVK+9B0cQK0Bv2YhBt
epQAnj44OYf66Kug6zZvRQd5SmzxE1Vv
=Rlnm
-----END PGP SIGNATURE-----
-- 
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.

diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -135,6 +135,10 @@
         else:
             return base.ResultProxy(self)
 
+    def post_exec(self):
+        for notice in self._connection.connection.notices:
+            self.engine.logger.info(notice)
+
 
 class PostgreSQL_psycopg2Compiler(PGCompiler):
     def visit_mod(self, binary, **kw):

Reply via email to