My code:
selectQ ="""SELECT * FROM %s WHERE %s = %%s order by RAND() limit %s""" % (self.table,self.columnSpecName,limit),
self.db.execute(str(selectQ),(idKey))
I get this exception:
mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''SELECT * FROM table WHERE person_oid = 16 order by RAND() limit 10',)' at line 1")
However if I copy the query and run it through mysql it runs just fine.
What am I overlooking ?
You should look closer to:
And you will see double apostrophe at the beginning of the query and
,)'at the end of it.You’ve got a comma at the end of the first line, making it a tuple
Remove it and you will not need
str(selectQ)on the second line.