Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

I utilize the accompanying code in Python (with pyodbc for a MS-Access base). 

cursor.execute("select a from tbl where b=? and c=?", (x, y))

It's Ok at the same time, for support/maintenance purposes, I need to realize the total and precise SQL string sends to the information database. 

Is it conceivable and how?

1 Answer

0 votes
by (26.4k points)

It actually diifers by the driver.

Look at the below two examples:

import MySQLdb

mc = MySQLdb.connect()

r = mc.cursor()

r.execute('select %s, %s', ("foo", 2))

r._executed

"select 'foo', 2"

import psycopg2

pc = psycopg2.connect()

r = pc.cursor()

r.execute('select %s, %s', ('foo', 2))

r.query

"select E'foo', 2"

Are you interested to learn the concepts of Python? Join the python training course fast!

Browse Categories

...