【发布时间】:2011-03-25 12:55:28
【问题描述】:
我正在使用 python 2.7 和 pymssql 1.9.908。
在 .net 中查询数据库我会这样做:
using (SqlCommand com = new SqlCommand("select * from Customer where CustomerId = @CustomerId", connection))
{
com.Parameters.AddWithValue("@CustomerID", CustomerID);
//Do something with the command
}
我试图弄清楚 python 的等价物,尤其是 pymssql。我意识到我可以只进行字符串格式化,但这似乎不能像参数那样正确处理转义(我可能错了)。
我如何在 python 中做到这一点?
【问题讨论】:
-
优秀的问题和答案。有谁知道如何使用 Jason 上面的 NAMED 参数。到目前为止,我只能使用 %s, %d 类型的东西(位置)。