From: SourceForge.net <no...@so...> - 2004-05-10 03:38:32
|
Patches item #931857, was opened at 2004-04-08 13:15 Message generated for change (Comment added) made by ballie01 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=316528&aid=931857&group_id=16528 Category: None Group: None >Status: Pending >Resolution: Fixed Priority: 5 Submitted By: Tim Middleton (ragica) >Assigned to: Billy G. Allie (ballie01) 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'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 'TEXT' 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 = ''. Examples:: from pyPgSQL import PgSQL # set the debug to the predefined TEXT output dbconn = PgSQL('db') dbconn.debug = "TEXT" # or setting from a Cursor object dbcurs = conn.Cursor() dbcurs.conn.debug = "Query Sent:\n%s\n" ---------------------------------------------------------------------- >Comment By: Billy G. Allie (ballie01) Date: 2004-05-09 23:38 Message: Logged In: YES user_id=8500 I have added the debug feature describe to the libpq.PgConnection object and made it accessable from the PgSQL.Connection object. It made more sense to me for it to be implemented in the lower level libpq module. The changes have been commited to CVS. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=316528&aid=931857&group_id=16528 |