Re: How to find out the exact SQL being executed?

"Billy G. Allie" <[email protected]> Thu, 29 Jul 2004 00:38:20 -0400
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jorge Godoy wrote:
| Hi!
|
|
| I'm trying to debug some code that involves dates and when I print the
| SQL statement to be executed, I don't think that all the substitutions
| and quotes are being correctly done. I'd like to find a way to print
| what is being executed at the 'cursor.execute()' command. Is there any
| way to do that?
|
| Some modules provide a way to print the statement, but I couldn't find
| this at pyPgSQL or its documentation.
|
|
| TIA,

Once you've opened a connection, you can toggle the printing of the
exact query sent to the database as follows:

|>> from pyPgSQL import PgSQL
|>> cx = PgSQL.connect()
|>> cx.conn.toggleShowQuery	<-- this toggles printing the query on
'on'
|>> cu = cx.cursor()
QUERY: BEGIN WORK
|>> cu.execute('select * from test where b = %s', 'bga')
QUERY: DECLARE "PgSQL_-40B25954" CURSOR FOR select * from test where b =
'bga'
QUERY: FETCH 1 FROM "PgSQL_-40B25954"
QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 23
QUERY: SELECT typname, -1 , typelem FROM pg_type WHERE oid = 1043

Accessing cx.conn.toggleShowQuery again will turn off the printing of
the queries.

- --
____       | Billy G. Allie    | Domain....: [email protected]
|  /|      | 7436 Hartwell     | MSN.......: [email protected]
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBCH88nmIkMXoVVdURAoerAKCbtt5nU6uQI6Ec6UTtMpFZvvtRWgCfUYU+
jcK5ev6ZHzxM6W5vWdeC/gs=
=dlye
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click