我正在执行无效的查询,但我希望能够准确查看 pymysql
正在执行的查询内容来调试它。有没有办法做这样的事情:
try:
self.cursor.execute(SQL, tuple(PARAMS))
except:
print (self.cursor.last_executed_statement) # ??
最佳答案
根据the documentation ,你应该能够做到:
print (self.cursor.statement)
This read-only property returns the last executed statement as a string. The
statement
property can be useful for debugging and displaying what was sent to the MySQL server.The string can contain multiple statements if a multiple-statement string was executed. This occurs for execute() with multi=True. In this case, the
statement
property contains the entire statement string and theexecute()
call returns an iterator that can be used to process results from the individual statements. Thestatement
property for this iterator shows statement strings for the individual statements.
关于python - 获取pymysql中执行的sql语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59205041/