From: Billy G. A. <bil...@mu...> - 2004-07-29 04:38:24
|
-----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....: Bil...@mu... | /| | 7436 Hartwell | MSN.......: B_G...@em... |-/-|----- | 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----- |