Python是否支持MySQL预备语句? [英] Does Python support MySQL prepared statements?
问题描述
早先我在一个PHP项目上工作,其中准备好的语句使SELECT查询的速度提高了20%.
I worked on a PHP project earlier where prepared statements made the SELECT queries 20% faster.
我想知道它是否可以在Python上运行吗?我似乎找不到任何明确表明可以使用或不可以使用的东西.
I'm wondering if it works on Python? I can't seem to find anything that specifically says it does or does NOT.
推荐答案
直接回答,不是的.
joshperry的答案很好地说明了它的作用.
joshperry's answer is a good explanation of what it does instead.
来自对类似问题的回答,
检查MySQLdb 软件包注释:
参数化"是通过在MySQLdb中转义字符串,然后将其盲目插入到查询中来完成的,而不是使用 MYSQL_STMT API.结果是unicode字符串必须经过两个 中间表示(编码字符串,转义编码字符串) 在数据库接收到它们之前.
"Parameterization" is done in MySQLdb by escaping strings and then blindly interpolating them into the query, instead of using the MYSQL_STMT API. As a result unicode strings have to go through two intermediate representations (encoded string, escaped encoded string) before they're received by the database.
所以答案是:不,不是.
So the answer is: No, it doesn't.
这篇关于Python是否支持MySQL预备语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!