[英]Error when formatting a String - ValueError: unsupported format character ',' (0x2c)
I'm formatting query strings to run on my database. 我正在格式化查询字符串以在数据库上运行。 I am getting a value error when I am trying to format using the % python string formatting method.
尝试使用%python字符串格式化方法进行格式化时,出现值错误。
The specific error says ValueError: unsupported format character ',' (0x2c) at index where the , occurs after rate. 特定错误说ValueError:在率之后出现的索引处不支持格式字符','(0x2c)。 So inside (locationId, userId, discountId, rate, <- that right there is what is causing the issue for some reason.
因此,在内部(locationId,userId,discountId,rate,<-表示存在某种原因导致此问题)。
insertQuery = "INSERT INTO maprateinfo (locationId, userId, discountId, rate, customizedDiscount) VALUES (%i, %i, i%, %f, -1)" % (location, employee, locationDiscount, rate)
How can I fix this so the string formats properly? 如何解决此问题,以便正确格式化字符串? Using python 2.5.
使用python 2.5
It looks to me like you have a simple typo in your VALUES statement: i%
should be %i
. 在我看来,您在VALUES语句中有一个简单的错字:
i%
应该是%i
。
Look into using a database layer that will handle doing all the necessary escaping for you (if you aren't already). 考虑使用一个数据库层,它将为您处理所有必需的转义操作(如果还没有的话)。 Otherwise, little Bobby Tables will take over your database.
否则,小鲍比表将接管您的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.