簡體   English   中英

如何使用cx_Oracle在Python cursor.execute中查看真正的SQL查詢

[英]How to see the real SQL query in Python cursor.execute using cx_Oracle

我在Python中使用以下代碼(使用CX_ORACLE作為oracle基礎)

con = cx_Oracle.connect(connectString)
cur = con.cursor()
sandy_pet_statement = 'select name, owner, type from cx_pets 
where owner = :owner and  anyparam= :any_param'
args = {':owner': sandy_id ,':any_param' = 'anyname'}
cur.execute(sandy_pet_statement,args )
res = cur.fetchall()

應用程序端的一個解決方案(與DB跟蹤相反)是子類,請參閱https://github.com/oracle/python-cx_Oracle/blob/master/samples/Subclassing.py

class Cursor(cx_Oracle.Cursor):

    def execute(self, statement, args):
        print("EXECUTE", statement)
        print("ARGS:")
        for argIndex, arg in enumerate(args):
            print("   ", argIndex + 1, "=>", repr(arg))
        return super(Cursor, self).execute(statement, args)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM