Dynamic sql for MySQLdb