print executed query

S

someone

Hello!

Is there a way to print a query for logging purpose as it was or will
be sent to database, if I don't escape values of query by myself?

cursor.execute(query, [id, somestring])

I could print query and values separate, but it would be great, if I
could see how query is constructed and can the also copy it and
execute in console.

Im using psycopg2, btw

Thanks!
 
P

Philip Semanchuk

Hello!

Is there a way to print a query for logging purpose as it was or will
be sent to database, if I don't escape values of query by myself?

cursor.execute(query, [id, somestring])

I could print query and values separate, but it would be great, if I
could see how query is constructed and can the also copy it and
execute in console.

Im using psycopg2, btw


If you can fiddle with the Postgres server settings, the server has
options for logging lots of things, including the queries it executes.


Hope this helps
Philip
 
S

someone

On Apr 29, 2010, at 12:01 PM, someone wrote:
Hello!
Is there a way to print a query for logging purpose as it was or will
be sent to database, if I don't escape values of query by myself?
cursor.execute(query, [id, somestring])
I could print query and values separate, but it would be great, if I
could see how query is constructed and can the also copy it and
execute in console.
Im using psycopg2, btw
If you can fiddle with the Postgres server settings, the server has options for logging lots of things, including the queries it executes.
Hope this helps
Philip

 smime.p7s
4KAnzeigenHerunterladen


Hello! Thanks for help! I've found much more simpler solution ;)

http://initd.org/psycopg/docs/cursor.html

query
Read-only attribute containing the body of the last query sent to the
backend (including bound arguments). None if no query has been
executed yet:
"INSERT INTO test (num, data) VALUES (42, E'bar')"

DB API extension The query attribute is a Psycopg extension to the DB
API 2.0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top