I am building a string with this method. But for some reason I am getting the following error
ValueError: unsupported format character ''' (0x27) at index 38
I have no idea where this is coming from. I checked for typos but nothing.
s = "SELECT %s FROM %s "
data = [colName, tableName]
if whereRoughly:
s+= "(WHERE "
for i in range(len(whereRoughly[0])):
s += "%s LIKE '%%s%' "
if i+1 < len(whereRoughly[0]): s += "OR "
data.append(whereRoughly[0][i])
data.append(whereRoughly[1])
s+= ")"
s += "ORDER BY %s;"
data.append("desc")
print s
print data
print s % tuple(data)
Here I call all the upper code
s.makeSelect(tableName="students", whereRoughly=([1,2], "Wes"))
This is the actual output
SELECT %s FROM %s (WHERE %s LIKE '%%s%' OR %s LIKE '%%s%' )ORDER BY %s;
['*', 'students', 1, 'Wes', 2, 'Wes', 'desc']
+=on strings in python. You should properly use combinations offormatandjoin.