我使用python 2.7和pymssql 1.9.908。如何在Python中使用SQL参数?
在.NET查询数据库,我会做这样的事情:
using (SqlCommand com = new SqlCommand("select * from Customer where CustomerId = @CustomerId", connection))
{
com.Parameters.AddWithValue("@CustomerID", CustomerID);
//Do something with the command
}
我试图找出相当于是什么蟒蛇,更特别pymssql。我意识到我可以做字符串格式化,但是这似乎并没有象参数那样正确地转义(我可能是错误的)。
如何在python中执行此操作?
优秀的问题和答案。有没有人知道如何使用* NAMED *参数,如杰森以上。到目前为止,我只能使用%s,%d类型的东西(位置)。 – 2013-12-05 18:49:45