How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

前端 未结 9 1415
有刺的猬
有刺的猬 2020-12-04 17:17

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

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

It\'

9条回答
  •  再見小時候
    2020-12-04 18:00

    It differs by driver. Here are 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"
    

提交回复
热议问题