Search code examples
pythonstringpython-2.5

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.

The specific error says ValueError: unsupported format character ',' (0x2c) at index where the , occurs after rate. So inside (locationId, userId, discountId, rate, <- that right there is what is causing the issue for some reason.

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.


Solution

  • It looks to me like you have a simple typo in your VALUES statement: i% should be %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.