【发布时间】:2020-08-17 12:11:38
【问题描述】:
我正在使用以下方法使用pymysql 对 SQL+args 查询进行参数化,但不执行它(至少合法):
try:
self.cursor.execute(self.sql + ' ***', self.sql_args or tuple())
except pymysql.err.ProgrammingError:
self._sql_formatted = self.cursor._last_executed.rstrip('* ')
实际上有没有pymysql 有一种方法,它只是格式化SQL 字符串而不执行它,还是我需要使用类似上面的方法?或者,另一种选择:
self.cursor.execute('DESCRIBE ' + self.sql, self.sql_args or tuple())
self._sql_formatted = self.cursor._last_executed.replace('DESCRIBE ', '')
【问题讨论】: