【发布时间】:2010-10-16 09:20:06
【问题描述】:
我是 python 新手,我来自 PHP 的土地。我根据我的 PHP 知识在 python 中构建了一个这样的 SQL 查询,我收到警告和错误
cursor_.execute("update posts set comment_count = comment_count + "+str(cursor_.rowcount)+" where ID = " + str(postid))
# rowcount here is int
形成查询的正确方法是什么?
另外,如何转义字符串以形成 SQL 安全字符串?比如如果我想转义 -、'、" 等,我曾经使用 addlashes。我们如何在 python 中做到这一点?
谢谢
【问题讨论】: