Patches item #931857, was opened at 2004-04-08 13:15
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=316528&aid=931857&group_id=16528
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Middleton (ragica)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add "debug" output hook in execute()
Initial Comment:
I have to use pygresql a lot. This patch provides something like one of the few things I miss from it when using pyPgSQL. The unified diff is against version 2.4. The changes are, of course, transparent. Perhaps there&#039;s a better way/place to do this, but this works for me. Perhaps others would find it handy.
It adds a "debug" attribute to the connection object, which is then used by the Cursor.execute() method.
Connection.debug may be set to provide a way of seeing processed SQL
queries immediately before they are executed.
If Connection.debug is set to a function, or other callable object,
the the call will be made with the query string as the argument.
If Connection.debug is set to a non-empty string that string will
have the query string substituted into it (using the %s code).
If Connection.debug is set to &#039;TEXT&#039; the query string will be printed
with added new-line and seperating rows surrounding it.
If Connection.debug is set to HTML or PRE then the query string will
be escaped and output within an HTML "div" or "pre" block. The block
will have a light grey background, and a thin dashed border. This is
useful for CGI debugging.
If Connection.debug is set to an empty string the query string
will simply be printed.
If Connection.debug is set to None (the default value) or a
non-callable non-string type it will be ignored.
Setting Connection.debug affects all cursors created by that connection.
You can of course set the Connection.debug from a Cursor object like
this: Cursor.conn.debug = &#039;&#039;.
Examples::
from pyPgSQL import PgSQL
# set the debug to the predefined TEXT output
dbconn = PgSQL(&#039;db&#039;)
dbconn.debug = "TEXT"
# or setting from a Cursor object
dbcurs = conn.Cursor()
dbcurs.conn.debug = "Query Sent:\n%s\n"
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=316528&aid=931857&group_id=16528