我使用 SQLAlchemy 记录执行的 sql(使用 echo=True
),以便我可以直接导入该文件(经过一些清理后)。问题是,该文件充满了以下内容:
INSERT INTO professors (department_id, id, first_name, last_name,
preferred_name, email_alias, user_id, created_at, updated_at, middle_name)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
很明显,它没有给我所需的字符串的最终形式。
最佳答案
您的问题分为两部分:
第一部分在这里回答:SQLAlchemy: print the actual query 。 在这方面,你的问题显然是重复的。
Read also How do I render SQL expressions as strings, possibly with bound parameters inlined? section of the official documentation.
第二部分是:如何使用上述内容使 SQLAlchemy 的
<logging
配置(sqlalchemy.engine
logger)记录查询。
对第二部分的简短回答是:如果不修改源代码就不能。看这个start line如果您决定使用它,请在存储库中。
关于mysql - SQLAlchemy 日志未写入最终字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29219136/